summaryrefslogtreecommitdiff
path: root/game/server/cstrike/holiday_gift.cpp
blob: afb2f0a666e479bf953f6f3b279970f3056a25fc (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "smokegrenade_projectile.h"
#include "sendproxy.h"
#include "holiday_gift.h"
#include "cs_player.h"
#include "KeyValues.h"
#include "bot_manager.h"
#include "weapon_csbase.h"

#define CHRISTMAS_MODEL "models/items/cs_gift.mdl"
												  
LINK_ENTITY_TO_CLASS( holiday_gift, CHolidayGift );
PRECACHE_WEAPON_REGISTER( holiday_gift );

//-----------------------------------------------------------------------------
CHolidayGift* CHolidayGift::Create( const Vector &position, const QAngle &angles, const QAngle &eyeAngles, const Vector &velocity, CBaseCombatCharacter *pOwner )
{
	CHolidayGift *pGift = (CHolidayGift*)CBaseEntity::Create( "holiday_gift", position, angles, pOwner );
	
	if ( pGift )
	{
		pGift->AddSpawnFlags( SF_NORESPAWN );

		Vector vecRight, vecUp;
		AngleVectors( eyeAngles, NULL, &vecRight, &vecUp );

		// Calculate the initial impulse on the gift.
		Vector vecImpulse( 0.0f, 0.0f, 0.0f );
		vecImpulse += vecUp * random->RandomFloat( 0, 0.25 );
		vecImpulse += vecRight * random->RandomFloat( -0.25, 0.25 );
		VectorNormalize( vecImpulse );
		vecImpulse *= random->RandomFloat( 100.0, 150.0 );
		vecImpulse += velocity;

		// Cap the impulse.
		float flSpeed = vecImpulse.Length();
		if ( flSpeed > 300.0 )
		{
			VectorScale( vecImpulse, 300.0 / flSpeed, vecImpulse );
		}

		pGift->SetMoveType( MOVETYPE_FLYGRAVITY );
		pGift->SetAbsVelocity( vecImpulse * 2.f + Vector(0,0,200) );
		pGift->SetAbsAngles( QAngle(0,0,0) );
		pGift->UseClientSideAnimation();
		pGift->ResetSequence( pGift->LookupSequence("idle") );

		pGift->EmitSound( "Christmas.GiftDrop" );

		pGift->ActivateWhenAtRest();
	}

	return pGift;
}

//-----------------------------------------------------------------------------
void CHolidayGift::Precache()
{
	BaseClass::Precache();

	PrecacheModel( CHRISTMAS_MODEL );
	PrecacheScriptSound( "Christmas.GiftDrop" );
	PrecacheScriptSound( "Christmas.GiftPickup" );
}

//-----------------------------------------------------------------------------
void CHolidayGift::Spawn( void )
{ 
	BaseClass::Spawn();

	SetModel( CHRISTMAS_MODEL );

	// Die in 30 seconds
	SetContextThink( &CBaseEntity::SUB_Remove, gpGlobals->curtime + 30, "DIE_THINK" );
	SetContextThink( &CHolidayGift::DropSoundThink, gpGlobals->curtime + 0.2f, "SOUND_THINK" );
}

//-----------------------------------------------------------------------------
void CHolidayGift::DropSoundThink( void )
{
	EmitSound( "Christmas.GiftDrop" );
}

//-----------------------------------------------------------------------------
bool CHolidayGift::MyTouch( CBasePlayer *pPlayer )
{
	if( !pPlayer )
		return false;

	if( !pPlayer->IsAlive() )
		return false;

	if ( pPlayer->IsBot() )
		return false;

	if ( ( pPlayer->GetTeamNumber() != TEAM_CT ) && ( pPlayer->GetTeamNumber() != TEAM_TERRORIST ) )
		return false;

	// Send a message for the achievement tracking.
	IGameEvent *event = gameeventmanager->CreateEvent( "christmas_gift_grab" );
	if ( event )
	{
		event->SetInt( "userid", pPlayer->GetUserID() );
		gameeventmanager->FireEvent( event );
	}
	pPlayer->EmitSound( "Christmas.GiftPickup" );

	return true;
}

//-----------------------------------------------------------------------------
void CHolidayGift::ItemTouch( CBaseEntity *pOther )
{
	if ( pOther->IsWorld() )
	{
		Vector absVel = GetAbsVelocity();
		SetAbsVelocity( Vector( 0,0,absVel.z ) );
		return;
	}

	BaseClass::ItemTouch( pOther );
}