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: CTF AmmoPack.
//
//=============================================================================//
#include "cbase.h"
#include "items.h"
#include "tf_gamerules.h"
#include "tf_shareddefs.h"
#include "tf_player.h"
#include "tf_team.h"
#include "engine/IEngineSound.h"
#include "entity_ammopack.h"
#include "tf_gamestats.h"
//=============================================================================
//
// CTF AmmoPack defines.
//
#define TF_AMMOPACK_PICKUP_SOUND "AmmoPack.Touch"
LINK_ENTITY_TO_CLASS( item_ammopack_full, CAmmoPack );
LINK_ENTITY_TO_CLASS( item_ammopack_small, CAmmoPackSmall );
LINK_ENTITY_TO_CLASS( item_ammopack_medium, CAmmoPackMedium );
//=============================================================================
//
// CTF AmmoPack functions.
//
//-----------------------------------------------------------------------------
// Purpose: Spawn function for the ammopack
//-----------------------------------------------------------------------------
void CAmmoPack::Spawn( void )
{
BaseClass::Spawn();
}
//-----------------------------------------------------------------------------
// Purpose: Precache function for the ammopack
//-----------------------------------------------------------------------------
void CAmmoPack::Precache( void )
{
PrecacheScriptSound( TF_AMMOPACK_PICKUP_SOUND );
PrecacheModel( TF_AMMOPACK_LARGE_BDAY ); // always precache this for PyroVision
BaseClass::Precache();
UpdateModelIndexOverrides();
}
//-----------------------------------------------------------------------------
// Purpose: MyTouch function for the ammopack
//-----------------------------------------------------------------------------
bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
{
bool bSuccess = false;
if ( ValidTouch( pPlayer ) )
{
CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
if ( !pTFPlayer )
return false;
float flPackRatio = PackRatios[GetPowerupSize()];
int iMaxPrimary = pTFPlayer->GetMaxAmmo(TF_AMMO_PRIMARY);
if ( pTFPlayer->GiveAmmo( ceil(iMaxPrimary * flPackRatio), TF_AMMO_PRIMARY, true, kAmmoSource_Pickup ) )
{
bSuccess = true;
}
int iMaxSecondary = pTFPlayer->GetMaxAmmo(TF_AMMO_SECONDARY);
if ( pTFPlayer->GiveAmmo( ceil(iMaxSecondary * flPackRatio), TF_AMMO_SECONDARY, true, kAmmoSource_Pickup ) )
{
bSuccess = true;
}
int iMaxMetal = pTFPlayer->GetMaxAmmo(TF_AMMO_METAL);
if ( pTFPlayer->GiveAmmo( ceil(iMaxMetal * flPackRatio), TF_AMMO_METAL, true, kAmmoSource_Pickup ) )
{
bSuccess = true;
}
if ( pTFPlayer->m_Shared.AddToSpyCloakMeter( 100.0f * flPackRatio ) )
{
bSuccess = true;
}
if ( pTFPlayer->AddToSpyKnife( 100.0f * flPackRatio, false ) )
{
bSuccess = true;
}
int iAmmoIsCharge = 0;
CALL_ATTRIB_HOOK_INT_ON_OTHER( pTFPlayer, iAmmoIsCharge, ammo_gives_charge );
if ( iAmmoIsCharge )
{
float flCurrentCharge = pTFPlayer->m_Shared.GetDemomanChargeMeter();
if ( flCurrentCharge < 100.0f )
{
pTFPlayer->m_Shared.SetDemomanChargeMeter( flCurrentCharge + flPackRatio * 100.0f );
bSuccess = true;
}
}
if ( pTFPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
{
int iMaxGrenades1 = pTFPlayer->GetMaxAmmo(TF_AMMO_GRENADES1);
if ( pTFPlayer->GiveAmmo( ceil(iMaxGrenades1 * flPackRatio), TF_AMMO_GRENADES1, true, kAmmoSource_Pickup ) )
{
bSuccess = true;
}
}
// did we give them anything?
if ( bSuccess )
{
CSingleUserRecipientFilter filter( pPlayer );
EmitSound( filter, entindex(), TF_AMMOPACK_PICKUP_SOUND );
CTF_GameStats.Event_PlayerAmmokitPickup( pTFPlayer );
IGameEvent * event = gameeventmanager->CreateEvent( "item_pickup" );
if( event )
{
event->SetInt( "userid", pPlayer->GetUserID() );
event->SetString( "item", GetAmmoPackName() );
gameeventmanager->FireEvent( event );
}
}
}
return bSuccess;
}
|