Example #1
0
bool PSpawnedVehicles::UnspawnVehicle( u32 nLocalId )
{
  u16 Index;
  PSpawnedVehicle* tVhc;

  if (( nLocalId <= mVhcBaseLocalId ) && ( nLocalId > ( mVhcBaseLocalId - mSpawnedVehicles.size() ) ) )
  {
    Index = mVhcBaseLocalId - nLocalId;
    tVhc = mSpawnedVehicles[Index];
    if ( tVhc )
    {
      if ( tVhc->GetInformation().GetStatus() != 2 )
      {
        tVhc->SetStatus( 0 );
      }
      delete tVhc;
      mSpawnedVehicles[Index] = NULL;
      if ( mNextFreeHint > Index )
      {
        mNextFreeHint = Index;
      }
      return true;
    }
  }

  return false;
}
Example #2
0
PSpawnedVehicle* PSpawnedVehicles::SpawnVehicle( PVehicleInformation const* nVhcInfo, PVhcCoordinates const* nVhcPos )
{
  PSpawnedVehicle* newVhc = NULL;
  u32 nSize;

  if ( nVhcInfo->GetStatus() == 0 ) // only if in garage
  {
    nSize = mSpawnedVehicles.size();
    while (( mNextFreeHint < nSize ) && mSpawnedVehicles[mNextFreeHint] )
    {
      ++mNextFreeHint;
    }
    if ( mNextFreeHint > nSize )
    {
      mNextFreeHint = nSize;
    }
    if ( mNextFreeHint == nSize )
    {
      mSpawnedVehicles.push_back( static_cast<PSpawnedVehicle *>(NULL) );
    }

    if ( mNextFreeHint < mMaxLocalVhc )
    {
      newVhc = new PSpawnedVehicle( mVhcBaseLocalId - mNextFreeHint, nVhcInfo, mLocation, nVhcPos );
      mSpawnedVehicles[mNextFreeHint++] = newVhc;
      newVhc->SetStatus( 1 );
    }
  }

  return newVhc;
}