CPlayer* CObjectSync::FindPlayerCloseToObject ( CObject* pObject, float fMaxDistance ) { // Grab the object position CVector vecPosition = pObject->GetPosition (); // See if any players are close enough CPlayer* pSyncer = NULL; list < CPlayer* > ::const_iterator iter = m_pPlayerManager->IterBegin (); for ( ; iter != m_pPlayerManager->IterEnd (); iter++ ) { CPlayer* pPlayer = *iter; // Is he joined? if ( pPlayer->IsJoined () ) { // Is he near the object? if ( IsPointNearPoint3D ( vecPosition, pPlayer->GetPosition (), fMaxDistance ) && ( pPlayer->GetDimension () == pObject->GetDimension () ) ) { // Prefer a player that syncs less objects if ( !pSyncer || pPlayer->CountSyncingObjects () < pSyncer->CountSyncingObjects () ) { pSyncer = pPlayer; } } } } // Return the player we found return pSyncer; }
CPlayer* CPedSync::FindPlayerCloseToPed ( CPed* pPed, float fMaxDistance ) { // Grab the ped position CVector vecPedPosition = pPed->GetPosition (); // See if any players are close enough CPlayer* pLastPlayerSyncing = NULL; CPlayer* pPlayer = NULL; list < CPlayer* > ::const_iterator iter = m_pPlayerManager->IterBegin (); for ( ; iter != m_pPlayerManager->IterEnd (); iter++ ) { pPlayer = *iter; // Is he joined? if ( pPlayer->IsJoined () ) { // He's near enough? if ( IsPointNearPoint3D ( vecPedPosition, pPlayer->GetPosition (), fMaxDistance ) ) { // Same dimension? if ( pPlayer->GetDimension () == pPed->GetDimension () ) { // He syncs less peds than the previous player close enough? if ( !pLastPlayerSyncing || pPlayer->CountSyncingPeds () < pLastPlayerSyncing->CountSyncingPeds () ) { pLastPlayerSyncing = pPlayer; } } } } } // Return the player we found that syncs the least number of peds return pLastPlayerSyncing; }
bool CClientCheckpoint::IsHit ( const CVector& vecPosition ) const { // Grab the type and do a 2D or 3D distance check depending on what type it is unsigned long ulType = GetCheckpointType (); if ( ulType == CClientCheckpoint::TYPE_NORMAL ) { return IsPointNearPoint2D ( m_Matrix.vPos, vecPosition, m_fSize + 4 ); } else { return IsPointNearPoint3D ( m_Matrix.vPos, vecPosition, m_fSize + 4 ); } }
void CObjectSync::UpdateObject ( CObject* pObject ) { CPlayer* pSyncer = pObject->GetSyncer (); // Does the object need to be synced? // We have no reason to sync static and unbreakable objects if ( !pObject->IsSyncable () || ( pObject->IsStatic () && !pObject->IsBreakable () ) ) { if ( pSyncer ) { // Tell the syncer to stop syncing StopSync ( pObject ); } return; } // Does the object have syncer? if ( pSyncer ) { // Does the syncer still near the object? if ( !IsPointNearPoint3D ( pSyncer->GetPosition (), pObject->GetPosition (), MAX_PLAYER_SYNC_DISTANCE ) || ( pObject->GetDimension () != pSyncer->GetDimension () ) ) { // Stop him from syncing it StopSync ( pObject ); // Find a new syncer FindSyncer ( pObject ); } } else { // Try to find a syncer FindSyncer ( pObject ); } }
void CPedSync::UpdatePed ( CPed* pPed ) { CPlayer* pSyncer = pPed->GetSyncer (); // Handle no syncing if ( !pPed->IsSyncable () ) { // This ped got a syncer? if ( pSyncer ) { // Tell the syncer to stop syncing StopSync ( pPed ); } return; } // This ped got a syncer? if ( pSyncer ) { // He isn't close enough to the ped and in the right dimension? if ( ( !IsPointNearPoint3D ( pSyncer->GetPosition (), pPed->GetPosition (), MAX_PLAYER_SYNC_DISTANCE ) ) || ( pPed->GetDimension () != pSyncer->GetDimension () ) ) { // Stop him from syncing it StopSync ( pPed ); // Find a new syncer for it FindSyncer ( pPed ); } } else { // Try to find a syncer for it FindSyncer ( pPed ); } }
bool CClient3DMarker::IsHit ( const CVector& vecPosition ) const { return IsPointNearPoint3D ( m_Matrix.vPos, vecPosition, m_fSize + 4 ); }
bool CClientColSphere::DoHitDetection ( const CVector& vecNowPosition, float fRadius ) { // Do a simple distance check between now position and our position return IsPointNearPoint3D ( vecNowPosition, m_vecPosition, fRadius + m_fRadius ); }