📄 tf_func_resource.cpp
字号:
{
vecOrigin = m_vecGatherPoint;
}
else if ( m_aSpawners.Size() )
{
// Return the first resource spawner
vecOrigin = m_aSpawners[0]->GetAbsOrigin();
}
else
{
vecOrigin = GetAbsOrigin();
}
vecAngles = QAngle(0,0,0);
return true;
}
int CResourceZone::GetBuildPointAttachmentIndex( int iPoint ) const
{
return 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::SetObjectOnBuildPoint( int iPoint, CBaseObject *pObject )
{
m_hResourcePump = pObject;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CResourceZone::GetNumObjectsOnMe( void )
{
if ( m_hResourcePump.Get() )
return 1;
return 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseEntity *CResourceZone::GetFirstObjectOnMe( void )
{
return m_hResourcePump;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseObject *CResourceZone::GetObjectOfTypeOnMe( int iObjectType )
{
if ( GetNumObjectsOnMe() == 1 )
{
CBaseObject *pObject = dynamic_cast<CBaseObject*>( m_hResourcePump.Get() );
if ( pObject )
{
if ( pObject->GetType() == iObjectType )
return pObject;
}
}
return NULL;
}
int CResourceZone::FindObjectOnBuildPoint( CBaseObject *pObject )
{
if (m_hResourcePump == pObject)
return 0;
return -1;
}
void CResourceZone::GetExitPoint( CBaseEntity *pPlayer, int iPoint, Vector *pAbsOrigin, QAngle *pAbsAngles )
{
Assert(0);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::RemoveAllObjects( void )
{
UTIL_Remove( m_hResourcePump );
}
//-----------------------------------------------------------------------------
// Purpose: Get the team that's gathering from this point
//-----------------------------------------------------------------------------
CTFTeam *CResourceZone::GetOwningTeam( void )
{
if ( m_iTeamGathering == -1 )
return NULL;
return (CTFTeam*)GetGlobalTeam(m_iTeamGathering);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::SetOwningTeam( int iTeamNumber )
{
m_iTeamGathering = iTeamNumber;
}
//-----------------------------------------------------------------------------
// Purpose: Transmit this to all players who are in commander mode
//-----------------------------------------------------------------------------
bool CResourceZone::ShouldTransmit( const edict_t *recipient, const void *pvs, int clientArea )
{
// Team rules may tell us that we should
CBaseEntity* pRecipientEntity = CBaseEntity::Instance( recipient );
if ( pRecipientEntity->IsPlayer() )
{
CBasePlayer *pPlayer = (CBasePlayer*)pRecipientEntity;
if ( pPlayer->GetTeam() )
{
if (pPlayer->GetTeam()->ShouldTransmitToPlayer( pPlayer, this ))
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Check to see if we should create any more resource chunks
//-----------------------------------------------------------------------------
bool CResourceZone::ShouldSpawnChunk( void )
{
// Don't spawn chunks if we're outta resources
if ( IsEmpty() )
return false;
// Create a chunk if we're below our max
if ( m_aChunks.Size() >= m_iMaxChunks )
return false;
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::SpawnChunk( const Vector &vecOrigin )
{
// ROBIN: Disabled for now
return;
TFStats()->IncrementStat( TF_STAT_RESOURCE_CHUNKS_SPAWNED, 1 );
// Create a resource chunk and add it to our list
Vector vecVelocity = Vector( random->RandomFloat( -100,100 ), random->RandomFloat( -100,100 ), random->RandomFloat( 300,600 ));
CResourceChunk *pChunk = CResourceChunk::Create( false, vecOrigin, vecVelocity );
pChunk->m_hZone = this;
// Add it to our list
m_aChunks.AddToTail( pChunk );
// Remove it's value from the zone
RemoveResources( pChunk->GetResourceValue() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::RecomputeClientResources( )
{
m_flClientResources = clamp( (float)m_nResourcesLeft / (float)m_nMaxResources, 0.0f, 1.0f );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::RemoveChunk( CResourceChunk *pChunk, bool bReturn )
{
if (bReturn)
{
TFStats()->IncrementStat( TF_STAT_RESOURCE_CHUNKS_RETIRED, 1 );
}
m_aChunks.FindAndRemove( pChunk );
// If I'm being returned, re-add my value to the resource level of the zone
if ( bReturn )
{
m_nResourcesLeft += pChunk->GetResourceValue();
RecomputeClientResources();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceZone::AddSpawner( CResourceSpawner *pSpawner )
{
m_aSpawners.AddToTail( pSpawner );
pSpawner->SetActive( GetActive() );
}
//========================================================================================================================
// RESOURCE CHUNK SPAWNER
//========================================================================================================================
LINK_ENTITY_TO_CLASS( env_resourcespawner, CResourceSpawner );
PRECACHE_REGISTER( env_resourcespawner );
BEGIN_DATADESC( CResourceSpawner )
// functions
DEFINE_FUNCTION( CResourceSpawner, SpawnChunkThink ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST(CResourceSpawner, DT_ResourceSpawner)
SendPropInt( SENDINFO( m_bActive ), 1, SPROP_UNSIGNED ),
END_SEND_TABLE();
// Resource Spawner Models
char *sResourceSpawnerModel = "models/resources/resource_spawner_B.mdl";
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceSpawner::Spawn( void )
{
m_hZone = NULL;
m_bActive = false;
SetModel( sResourceSpawnerModel );
// Create the object in the physics system
/*
VPhysicsInitStatic();
*/
SetMoveType( MOVETYPE_NONE );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceSpawner::Precache( void )
{
engine->PrecacheModel( sResourceSpawnerModel );
}
//-----------------------------------------------------------------------------
// Purpose: Find my resource point
//-----------------------------------------------------------------------------
void CResourceSpawner::Activate( void )
{
if ( m_target != NULL_STRING )
{
// Find my resource zone
CResourceZone *pZone = (CResourceZone*)gEntList.FindEntityByName( NULL, m_target, NULL );
if ( pZone )
{
m_hZone = pZone;
SetModel( sResourceSpawnerModel );
m_hZone->AddSpawner( this );
return;
}
}
Warning( "ERROR: Resource Spawner without a target resource zone specified.\n" );
UTIL_Remove( this );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CResourceSpawner::SetActive( bool bActive )
{
// Going active?
if ( !m_bActive && bActive )
{
// Randomize the thinks a little to reduce network usage ong chunk spawning
SetNextThink( gpGlobals->curtime + m_hZone->GetResourceRate() + random->RandomFloat( 0.0, 1.0 ) );
SetThink( SpawnChunkThink );
m_fEffects &= ~EF_NODRAW;
}
else if ( m_bActive && !bActive )
{
// Going inactive
SetThink( NULL );
m_fEffects |= EF_NODRAW;
}
m_bActive = bActive;
}
//-----------------------------------------------------------------------------
// Purpose: Spawn a chunk from this spawner
//-----------------------------------------------------------------------------
void CResourceSpawner::SpawnChunkThink( void )
{
// Lost our zone?
if ( !m_hZone )
{
SetActive( false );
return;
}
if ( m_hZone->ShouldSpawnChunk() )
{
// Start spawning events
CEntityMessageFilter filter( this, "CResourceSpawner" );
MessageBegin( filter, 0 );
MessageEnd();
m_hZone->SpawnChunk( GetAbsOrigin() + Vector(0,0,64) );
}
// Randomize the thinks a little to reduce network usage on chunk spawning
SetNextThink( gpGlobals->curtime + m_hZone->GetResourceRate() + random->RandomFloat( 0.0, 1.0 ) );
}
//-----------------------------------------------------------------------------
// Purpose: Convert an amount of resources into a number of processed & unprocessed resource chunks
//-----------------------------------------------------------------------------
void ConvertResourceValueToChunks( int iResources, int *iNumProcessed, int *iNumNormal )
{
*iNumProcessed = *iNumNormal = 0;
while ( iResources >= resource_chunk_processed_value.GetFloat() )
{
iResources -= resource_chunk_processed_value.GetFloat();
*iNumProcessed += 1;
}
while ( iResources >= resource_chunk_value.GetFloat() )
{
iResources -= resource_chunk_value.GetFloat();
*iNumNormal += 1;
}
// Round up
if ( iResources )
{
*iNumNormal++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -