예제 #1
0
//-----------------------------------------------------------------------------
// Purpose: Check to see if our target has moved beyond our length
//-----------------------------------------------------------------------------
void CHarpoon::ConstrainThink( void )
{
	if ( !GetImpaledTarget() || !m_hLinkedHarpoon.Get() )
		return;

	// Moved too far away?
	float flDistSq = m_hLinkedHarpoon->GetAbsOrigin().DistToSqr( GetImpaledTarget()->GetAbsOrigin() ); 
	if ( flDistSq > m_flConstrainLength )
	{
		// Break the rope
		if ( m_hRope )
		{
			m_hRope->DetachPoint(1);
			m_hRope->DieAtNextRest();
			m_hRope = NULL;
		}

		// If we're impaling a player, remove his movement constraint
		if ( GetImpaledTarget()->IsPlayer() )
		{
			CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)GetImpaledTarget();
			pPlayer->DeactivateMovementConstraint();
		}

		SetThink( NULL );
	}
	else
	{
		SetNextThink( gpGlobals->curtime + 0.1f );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Detach the player from the "Buff Station."
//-----------------------------------------------------------------------------
void CObjectBuffStation::DetachPlayerByIndex( int nIndex )
{
	// Valid index?
	Assert( nIndex < BUFF_STATION_MAX_PLAYERS );

	// Get the player.
	CBaseTFPlayer *pPlayer = m_hPlayers[nIndex].Get();
	if ( !pPlayer )
	{
		m_hPlayers.Set( nIndex, NULL );
		return;
	}

	// Remove the damage modifier.
	m_aPlayerAttachInfo[nIndex].m_DamageModifier.RemoveModifier();

	// Remove the rope (cable).
	if ( m_aPlayerAttachInfo[nIndex].m_hRope.Get() )
	{
		m_aPlayerAttachInfo[nIndex].m_hRope->DetachPoint( 1 );
		m_aPlayerAttachInfo[nIndex].m_hRope->DieAtNextRest();
	}

	// Unconstrain the player movement.
	pPlayer->DeactivateMovementConstraint();

	// Keep track of player events.
	g_pNotify->RemoveEntity( this, pPlayer );

	// Reduce player count.
	m_nPlayerCount--;
	m_hPlayers.Set( nIndex, NULL );
}