void WorldModel::HandleAttachMsg( const CParsedMsg &cMsg, const char *szClass ) { if( cMsg.GetArgCount() >= 2 && !szClass ) { // Look for the specific objects we want to attach for( uint i = 1; i < cMsg.GetArgCount( ); i++ ) { const char *pObjName = cMsg.GetArg(i).c_str(); if( !pObjName ) break; ObjArray<HOBJECT, 1> objArray; g_pLTServer->FindNamedObjects( const_cast<char*>(pObjName), objArray ); if( objArray.NumObjects() ) { AttachObject( objArray.GetObject( 0 ) ); } } } else { if( m_vAttachDir.MagSqr() > 1.0f ) { // Grab an object in the direction of the attach vector and attach it IntersectQuery IQuery; IntersectInfo IInfo; g_pLTServer->GetObjectPos( m_hObject, &IQuery.m_From ); IQuery.m_To = IQuery.m_From + m_vAttachDir; IQuery.m_Flags = INTERSECT_OBJECTS | IGNORE_NONSOLID; if( g_pLTServer->IntersectSegment( &IQuery, &IInfo ) ) { // Only attach objects of a specific class type... if( IInfo.m_hObject && IsKindOf( IInfo.m_hObject, szClass )) { if( m_hAttachDirObj ) DetachObject( m_hAttachDirObj ); m_hAttachDirObj = IInfo.m_hObject; AttachObject( m_hAttachDirObj ); } } } else { LTVector vPos; LTRotation rRot; LTMatrix mMat; g_pLTServer->GetObjectPos( m_hObject, &vPos ); g_pLTServer->GetObjectRotation( m_hObject, &rRot ); rRot.ConvertToMatrix( mMat ); LTVector vMin, vMax, vDims; g_pPhysicsLT->GetObjectDims( m_hObject, &vDims ); vMin = mMat * (vPos - vDims); vMax = mMat * (vPos + vDims); ObjectList *pObjList = g_pLTServer->GetBoxIntersecters( &vMin, &vMax ); if( !pObjList ) return; HOBJECT hObj; ObjectLink *pLink = pObjList->m_pFirstLink; while( pLink ) { hObj = pLink->m_hObject; if( hObj && IsKindOf( hObj, szClass )) { AttachObject( hObj ); // add it to our list of objects attached via the ATTACH message... LTObjRefNotifier ref( *this ); ref = hObj; m_AttachMsgObjList.push_back( ref ); } pLink = pLink->m_pNext; } g_pLTServer->RelinquishList( pObjList ); pObjList = NULL; } } }