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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Resource chunks
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_func_resource.h"
#include "tf_team.h"
#include "tf_basecombatweapon.h"
#include "tf_obj.h"
#include "resource_chunk.h"
#include "vstdlib/random.h"
#include "tf_stats.h"
#include "engine/IEngineSound.h"
ConVar resource_chunk_value( "resource_chunk_value","20", FCVAR_NONE, "Resource value of a single resource chunk." );
ConVar resource_chunk_processed_value( "resource_chunk_processed_value","80", FCVAR_NONE, "Resource value of a single processed resource chunk." );
// Resource Chunk Models
char *sResourceChunkModel = "models/resources/resource_chunk_B.mdl";
char *sProcessedResourceChunkModel = "models/resources/processed_resource_chunk_B.mdl";
BEGIN_DATADESC( CResourceChunk )
// functions
DEFINE_FUNCTION( ChunkTouch ),
DEFINE_FUNCTION( ChunkRemove ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CResourceChunk, DT_ResourceChunk )
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( resource_chunk, CResourceChunk );
PRECACHE_REGISTER( resource_chunk );
//-----------------------------------------------------------------------------
// Purpose: Remove me from any lists I'm in when I'm deleted
//-----------------------------------------------------------------------------
void CResourceChunk::UpdateOnRemove( void )
{
if ( m_hZone )
{
m_hZone->RemoveChunk( this, false );
m_hZone = NULL;
}
// Chain at end to mimic destructor unwind order
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceChunk::Spawn( )
{
// Init model
if ( IsProcessed() )
{
SetModelName( AllocPooledString( sProcessedResourceChunkModel ) );
}
else
{
SetModelName( AllocPooledString( sResourceChunkModel ) );
}
BaseClass::Spawn();
UTIL_SetSize( this, Vector(-4,-4,-4), Vector(4,4,4) );
SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );
SetSolid( SOLID_BBOX );
AddSolidFlags( FSOLID_TRIGGER );
CollisionProp()->UseTriggerBounds( true, 24 );
SetCollisionGroup( TFCOLLISION_GROUP_RESOURCE_CHUNK );
SetGravity( 1.0 );
SetFriction( 1 );
SetTouch( ChunkTouch );
SetThink( ChunkRemove );
SetNextThink( gpGlobals->curtime + random->RandomFloat( 50.0, 80.0 ) ); // Remove myself the
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceChunk::Precache( void )
{
PrecacheModel( sResourceChunkModel );
PrecacheModel( sProcessedResourceChunkModel );
PrecacheModel( "sprites/redglow1.vmt" );
PrecacheScriptSound( "ResourceChunk.Pickup" );
}
//-----------------------------------------------------------------------------
// Purpose: Create a resource chunk
//-----------------------------------------------------------------------------
CResourceChunk *CResourceChunk::Create( bool bProcessed, const Vector &vecOrigin, const Vector &vecVelocity )
{
CResourceChunk *pChunk = (CResourceChunk*)CreateEntityByName("resource_chunk");
UTIL_SetOrigin( pChunk, vecOrigin );
pChunk->m_bIsProcessed = bProcessed;
pChunk->m_bBeingCollected = false;
pChunk->Spawn();
pChunk->SetAbsVelocity( vecVelocity );
pChunk->SetLocalAngularVelocity( RandomAngle( -100, 100 ) );
pChunk->SetLocalAngles( vec3_angle );
return pChunk;
}
//-----------------------------------------------------------------------------
// Purpose: If we're picked up by another pla`yer, give resources to that team
//-----------------------------------------------------------------------------
void CResourceChunk::ChunkTouch( CBaseEntity *pOther )
{
if ( pOther->IsPlayer() || pOther->GetServerVehicle() )
{
// Give the team the resources
int iAmountPerPlayer = ((CTFTeam *)pOther->GetTeam())->AddTeamResources( GetResourceValue(), TF_PLAYER_STAT_RESOURCES_ACQUIRED_FROM_CHUNKS );
TFStats()->IncrementTeamStat( pOther->GetTeamNumber(), TF_TEAM_STAT_RESOURCE_CHUNKS_COLLECTED, GetResourceValue() );
pOther->EmitSound( "ResourceChunk.Pickup" );
// Tell the player
CSingleUserRecipientFilter user( (CBasePlayer*)pOther );
UserMessageBegin( user, "PickupRes" );
WRITE_BYTE( iAmountPerPlayer );
MessageEnd();
// Tell our zone to remove this chunk from it's list
if ( m_hZone )
{
m_hZone->RemoveChunk( this, false );
m_hZone = NULL;
}
// Remove this chunk
SetTouch( NULL );
UTIL_Remove( this );
return;
}
}
//-----------------------------------------------------------------------------
// Purpose: Remove myself if I'm not being harvested
//-----------------------------------------------------------------------------
void CResourceChunk::ChunkRemove( void )
{
// Remove this chunk
if ( m_hZone )
{
m_hZone->RemoveChunk( this, true );
m_hZone = NULL;
}
UTIL_Remove( this );
}
//-----------------------------------------------------------------------------
// Purpose: Return the resource value of this chunk
//-----------------------------------------------------------------------------
float CResourceChunk::GetResourceValue( void )
{
// Init value & model
if ( IsProcessed() )
return resource_chunk_processed_value.GetFloat();
return resource_chunk_value.GetFloat();
}
|