diff --git a/src/game/server/tf/entity_currencypack.cpp b/src/game/server/tf/entity_currencypack.cpp index 480f9d50394..fb5aeadf097 100644 --- a/src/game/server/tf/entity_currencypack.cpp +++ b/src/game/server/tf/entity_currencypack.cpp @@ -174,40 +174,31 @@ void CCurrencyPack::BlinkThink( void ) //----------------------------------------------------------------------------- -// Become touchable when we are at rest +// Purpose: Collect this pack when it comes to rest if it is outside the playable space. //----------------------------------------------------------------------------- void CCurrencyPack::ComeToRest( void ) { BaseClass::ComeToRest(); - if ( IsClaimed() || m_bDistributed ) + // I'm not sure when this should ever actually return true, but it doesn't seem to cause any issues so I'm not touching it. + if ( IsClaimed() ) return; // if we've come to rest in an area with no nav, just grant the money to the player if ( TheNavMesh->GetNavArea( GetAbsOrigin() ) == NULL ) { - TFGameRules()->DistributeCurrencyAmount( m_nAmount ); - m_bTouched = true; - UTIL_Remove( this ); - + AutoCollect(); return; } // See if we've come to rest in a trigger_hurt for ( int i = 0; i < ITriggerHurtAutoList::AutoList().Count(); i++ ) { - CTriggerHurt *pTrigger = static_cast( ITriggerHurtAutoList::AutoList()[i] ); - if ( !pTrigger->m_bDisabled ) + CTriggerHurt *pTrigger = static_cast( ITriggerHurtAutoList::AutoList()[ i ] ); + if ( !pTrigger->m_bDisabled && pTrigger->PointIsWithin( GetAbsOrigin() ) ) { - Vector vecMins, vecMaxs; - pTrigger->GetCollideable()->WorldSpaceSurroundingBounds( &vecMins, &vecMaxs ); - if ( IsPointInBox( GetCollideable()->GetCollisionOrigin(), vecMins, vecMaxs ) ) - { - TFGameRules()->DistributeCurrencyAmount( m_nAmount ); - - m_bTouched = true; - UTIL_Remove( this ); - } + AutoCollect(); + return; } } @@ -215,18 +206,27 @@ void CCurrencyPack::ComeToRest( void ) for ( int i = 0; i < IFuncRespawnRoomAutoList::AutoList().Count(); i++ ) { CFuncRespawnRoom *pRespawnRoom = static_cast( IFuncRespawnRoomAutoList::AutoList()[ i ] ); - Vector vecMins, vecMaxs; - pRespawnRoom->GetCollideable()->WorldSpaceSurroundingBounds( &vecMins, &vecMaxs ); - if ( IsPointInBox( GetCollideable()->GetCollisionOrigin(), vecMins, vecMaxs ) ) + if ( !pRespawnRoom->m_bDisabled && pRespawnRoom->PointIsWithin( GetAbsOrigin() ) ) { - TFGameRules()->DistributeCurrencyAmount( m_nAmount ); - - m_bTouched = true; - UTIL_Remove( this ); + AutoCollect(); + return; } } } +//----------------------------------------------------------------------------- +// Purpose: Collects the pack, crediting the player team appropriately. Intended for when a pack lands outside the playable space. +//----------------------------------------------------------------------------- +void CCurrencyPack::AutoCollect( void ) +{ + if ( !m_bDistributed ) + { + TFGameRules()->DistributeCurrencyAmount( m_nAmount ); + } + m_bTouched = true; + UTIL_Remove( this ); +} + //----------------------------------------------------------------------------- // Purpose: Sets the value of a custom pack //----------------------------------------------------------------------------- diff --git a/src/game/server/tf/entity_currencypack.h b/src/game/server/tf/entity_currencypack.h index 565bc79041c..fe59fa7cdc1 100644 --- a/src/game/server/tf/entity_currencypack.h +++ b/src/game/server/tf/entity_currencypack.h @@ -39,6 +39,7 @@ class CCurrencyPack : public CTFPowerup, public ICurrencyPackAutoList bool MyTouch( CBasePlayer *pPlayer ); virtual bool AffectedByRadiusCollection() const { return true; } + void AutoCollect( void ); void SetAmount( float flAmount ); void SetClaimed( void ) { m_bClaimed = true; } // Radius collection code "steers" packs toward the player bool IsClaimed( void ) { return m_bClaimed; } // So don't allow other players to interfere