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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A team's resource processor back at their base
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_team.h"
#include "info_resourceprocessor.h"
#include "tf_player.h"
#include "npc_minicarrier.h"
#include "tf_gamerules.h"
BEGIN_DATADESC( CResourceProcessor )
// functions
DEFINE_FUNCTION( ProcessorTouch ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST(CResourceProcessor, DT_ResourceProcessor)
END_SEND_TABLE()
LINK_ENTITY_TO_CLASS( info_resourceprocessor, CResourceProcessor);
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceProcessor::Spawn( void )
{
Precache();
SetSolid( SOLID_SLIDEBOX );
SetMoveType( MOVETYPE_NONE );
AddFlag( FL_NOTARGET );
UTIL_SetSize( pev, Vector(-32,-32,0), Vector(32,32, 128) );
SetModel( "models/objects/obj_resourceprocessor.mdl" );
SetTouch( ProcessorTouch );
m_flHackSpawnHeight = 256;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceProcessor::Precache( void )
{
PrecacheModel( "models/objects/obj_resourceprocessor.mdl" );
UTIL_PrecacheOther( "npc_minicarrier" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceProcessor::Activate( void )
{
BaseClass::Activate();
if ( GetTeamNumber() < 0 || GetTeamNumber() >= GetNumberOfTeams() )
{
Warning( "Warning, info_resourceprocessor with invalid Team Number set.\n" );
UTIL_Remove( this );
return;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceProcessor::ProcessorTouch( CBaseEntity *pOther )
{
// Players
if ( pOther->IsPlayer() )
{
// Ignore touches from enemy players
if ( !InSameTeam( pOther ) )
return;
CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)pOther;
// Remove all the player's resources and add them to the team's stash
for ( int i = 0; i < MAX_RESOURCE_TYPES; i++ )
{
int iCount = pPlayer->GetResourceChunkCount(i, false);
if ( iCount )
{
pPlayer->RemoveResourceChunks( i, iCount, false );
AddResources( i, iCount * CHUNK_RESOURCE_VALUE );
}
// Now remove processed versions too
iCount = pPlayer->GetResourceChunkCount(i, true);
if ( iCount )
{
pPlayer->RemoveResourceChunks( i, iCount, true );
AddResources( i, iCount * PROCESSED_CHUNK_RESOURCE_VALUE );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Add resources to the processor, and hence the team's bank
//-----------------------------------------------------------------------------
void CResourceProcessor::AddResources( int iResourceType, float flResources )
{
if ( !GetTeam() )
return;
((CTFTeam *)GetTeam())->AddResources( iResourceType, flResources );
((CTFTeam *)GetTeam())->ResourceLoadDeposited();
}
//-----------------------------------------------------------------------------
// Purpose: Spawn a minicarrier
//-----------------------------------------------------------------------------
void CResourceProcessor::SpawnMiniCarrier( void )
{
CNPC_MiniCarrier *pMiniCarrier = (CNPC_MiniCarrier*)CreateEntityByName( "npc_minicarrier" );
pMiniCarrier->Spawn();
pMiniCarrier->ChangeTeam( m_iTeamNumber );
// Find a clear spot near me & spawn in it
if ( !EntityPlacementTest( pMiniCarrier, GetAbsOrigin() + Vector(0,0,m_flHackSpawnHeight),
pMiniCarrier->GetAbsOrigin(), false ) )
{
Warning( "Failed to find empty space to spawn a minicarrier.\n" );
( ( CTFTeam * )GetTeam() )->RemoveRobot( pMiniCarrier );
UTIL_Remove( pMiniCarrier );
return;
}
m_flHackSpawnHeight += 64;
engine->SetOrigin( pMiniCarrier->pev, pMiniCarrier->GetOrigin() );
pMiniCarrier->SetHomeProcessor( this );
}
|