summaryrefslogtreecommitdiff
path: root/game/shared/tf/entity_bonuspack.cpp
blob: 1d2af24ffbfbcca3dcff54e1fa078d5c39c08dd3 (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
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: CTF HealthKit.
//
//=============================================================================//
#include "cbase.h"
#include "entity_bonuspack.h"

#ifdef GAME_DLL
	#include "tf_logic_robot_destruction.h"
	#include "tf_player.h"
	#include "particle_parse.h"
	#include "tf_fx.h"
#endif

#define TF_POWERCORE_RED_PICKUP "powercore_embers_red"
#define TF_POWERCORE_BLUE_PICKUP "powercore_embers_blue"
#define BONUS_PACK_BLINK_CONTEXT "blink_think"

ConVar tf_bonuspack_score( "tf_bonuspack_score", "1", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY );
#define BLINK_TIME 5.f
#define REMOVE_TIME 20.f
#define PICKUP_TIME 0.5f

IMPLEMENT_NETWORKCLASS_ALIASED( BonusPack, DT_CBonusPack )

BEGIN_NETWORK_TABLE( CBonusPack, DT_CBonusPack  )
END_NETWORK_TABLE()

BEGIN_DATADESC( CBonusPack )
END_DATADESC()

LINK_ENTITY_TO_CLASS( item_bonuspack, CBonusPack );

IMPLEMENT_AUTO_LIST( IBonusPackAutoList );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CBonusPack::CBonusPack()
{
#ifdef GAME_DLL
	m_bAutoMaterialize = false;
#else
	SetCycle( RandomFloat() );
#endif
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBonusPack::Spawn( void )
{
	Precache();
	BaseClass::BaseClass::Spawn();

#ifdef GAME_DLL
	const char *pszParticleName = GetTeamNumber() == TF_TEAM_RED ? "powercore_alert_blue" : "powercore_alert_red";
	DispatchParticleEffect( pszParticleName, PATTACH_POINT_FOLLOW, this, "particle_spawn" );

	SetModel( GetPowerupModel() );
	CollisionProp()->UseTriggerBounds( true, 64 );
	m_flCanPickupTime = gpGlobals->curtime + PICKUP_TIME;
	m_nBlinkCount = 0;
	m_flKillTime = gpGlobals->curtime + REMOVE_TIME + BLINK_TIME;
	SetContextThink( &CBonusPack::BlinkThink, gpGlobals->curtime + REMOVE_TIME, BONUS_PACK_BLINK_CONTEXT );
	SetContextThink( &CBonusPack::SUB_Remove, m_flKillTime, "RemoveThink" );
#endif
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBonusPack::Precache( void )
{
	// We deliberately allow late precaches here
	bool bAllowPrecache = CBaseEntity::IsPrecacheAllowed();
	CBaseEntity::SetAllowPrecache( true );
	PrecacheParticleSystem( TF_POWERCORE_RED_PICKUP );
	PrecacheParticleSystem( TF_POWERCORE_BLUE_PICKUP );
	BaseClass::Precache();
	CBaseEntity::SetAllowPrecache( bAllowPrecache );
}

#ifdef GAME_DLL
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBonusPack::MyTouch( CBasePlayer *pPlayer )
{
	if ( ValidTouch( pPlayer ) && gpGlobals->curtime >= m_flCanPickupTime )
	{
		CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
		if ( !pTFPlayer )
			return true;

		// Play a particle colored the color of the player that picked it up
		Vector vecOrigin = GetAbsOrigin() + Vector( 0,0,5 );
		CPVSFilter pvsfilter( vecOrigin );
		const char *pszParticleName = pPlayer->GetTeamNumber() == TF_TEAM_RED ? TF_POWERCORE_RED_PICKUP : TF_POWERCORE_BLUE_PICKUP;
		TE_TFParticleEffect( pvsfilter, 0.f, pszParticleName, vecOrigin, vec3_angle );

 		if ( CTFRobotDestructionLogic::GetRobotDestructionLogic() )
 		{
 			CTFRobotDestructionLogic::GetRobotDestructionLogic()->ScorePoints( GetTeamNumber()
																			  , tf_bonuspack_score.GetInt()
																			  , SCORE_CORES_COLLECTED
																			  , ToTFPlayer( pPlayer ) );
 		}

		int iBoostMax = pTFPlayer->m_Shared.GetMaxBuffedHealth();
		// Cap it to the max we'll boost a player's health
		int nHealthToAdd = clamp( 5, 0, iBoostMax - pTFPlayer->GetHealth() );
		// Give health
		pPlayer->TakeHealth( nHealthToAdd, DMG_GENERIC | DMG_IGNORE_MAXHEALTH );

		for ( int i=0;i<TF_AMMO_COUNT;i++ )
		{
			pPlayer->GiveAmmo( 5, i );
		}

		pPlayer->SetLastObjectiveTime( gpGlobals->curtime );

		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBonusPack::ValidTouch( CBasePlayer *pPlayer )
{
	if( pPlayer->GetTeamNumber() != GetTeamNumber() )
		return false;

	CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
	if ( !pTFPlayer )
		return false;

	// No invis spies
	if ( pTFPlayer->m_Shared.InCond( TF_COND_STEALTHED ) || pTFPlayer->m_Shared.GetPercentInvisible() > 0.25f )
		return false;

	// No disguised spies
	if ( pTFPlayer->m_Shared.InCond( TF_COND_DISGUISED ) || pTFPlayer->m_Shared.InCond( TF_COND_DISGUISING ) )
		return false;

	// No bonk'd scouts
	if ( pTFPlayer->m_Shared.InCond( TF_COND_PHASE ) || pTFPlayer->m_Shared.InCond( TF_COND_PASSTIME_INTERCEPTION ) )
		return false;

	// No teleporting players
	if ( pTFPlayer->m_Shared.InCond( TF_COND_SELECTED_TO_TELEPORT ) )
		return false;

	// No invulns
	if ( pTFPlayer->m_Shared.IsInvulnerable() )
		return false;

	return BaseClass::ValidTouch( pPlayer );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBonusPack::BlinkThink()
{
	float flTimeToKill = m_flKillTime - gpGlobals->curtime;
	float flNextBlink = RemapValClamped( flTimeToKill, BLINK_TIME, 0.f, 0.5f, 0.1f );

	SetContextThink( &CBonusPack::BlinkThink, gpGlobals->curtime + flNextBlink, BONUS_PACK_BLINK_CONTEXT );

	SetRenderMode( kRenderTransAlpha );

	++m_nBlinkCount;
	if ( m_nBlinkCount % 2 == 0 )
	{
		SetRenderColorA( 25 );
	}
	else
	{
		SetRenderColorA( 255 );
	}
}
#endif