void CClientTools::DetachFromEntity( EntitySearchResult entityToDetach ) { C_BaseEntity *ent = reinterpret_cast< C_BaseEntity * >( entityToDetach ); Assert( ent ); if ( !ent ) return; HTOOLHANDLE handle = ent->GetToolHandle(); ent->SetToolHandle( (HTOOLHANDLE)0 ); if ( handle == (HTOOLHANDLE)0 ) { Assert( 0 ); return; } int idx = m_Handles.Find( HToolEntry_t( handle ) ); if ( idx == m_Handles.InvalidIndex() ) { Assert( 0 ); return; } m_Handles.RemoveAt( idx ); m_ActiveHandles.FindAndRemove( handle ); }
HTOOLHANDLE CClientTools::GetToolHandleForEntityByIndex( int entindex ) { C_BaseEntity *ent = C_BaseEntity::Instance( entindex ); if ( !ent ) return (HTOOLHANDLE)0; return ent->GetToolHandle(); }
HTOOLHANDLE CClientTools::AttachToEntity( EntitySearchResult entityToAttach ) { C_BaseEntity *ent = reinterpret_cast< C_BaseEntity * >( entityToAttach ); if ( !ent ) return (HTOOLHANDLE)0; HTOOLHANDLE curHandle = ent->GetToolHandle(); if ( curHandle != 0 ) return curHandle; // Already attaached HToolEntry_t newHandle( s_nNextHandle++, ent ); m_Handles.Insert( newHandle ); m_ActiveHandles.AddToTail( newHandle.m_Handle ); return (HTOOLHANDLE)newHandle.m_Handle; }