public static bool GetSpawnCoords(ImprovedSpawnGroup spawnGroup, Vector3D startCoords, out Vector3D spawnCoords)
        {
            spawnCoords = Vector3D.Zero;
            SpawnResources.RefreshEntityLists();
            MyPlanet planet        = SpawnResources.GetNearestPlanet(startCoords);
            var      planetEntity  = planet as IMyEntity;
            double   extraDistance = 0;
            double   terrainVarianceCheckTarget = Settings.PlanetaryInstallations.SmallTerrainCheckDistance;

            if (planetEntity == null || planet == null)
            {
                Logger.AddMsg("Planet Somehow Doesn't Exist... Even Though It Should If Script Got Here...", true);
                return(false);
            }

            if (spawnGroup.PlanetaryInstallationType == "Medium")
            {
                extraDistance = Settings.PlanetaryInstallations.MediumSpawnDistanceIncrement;
                terrainVarianceCheckTarget = Settings.PlanetaryInstallations.MediumTerrainCheckDistance;
            }

            if (spawnGroup.PlanetaryInstallationType == "Large")
            {
                extraDistance = Settings.PlanetaryInstallations.LargeSpawnDistanceIncrement;
                terrainVarianceCheckTarget = Settings.PlanetaryInstallations.LargeTerrainCheckDistance;
            }

            var startDist    = Settings.PlanetaryInstallations.MinimumSpawnDistanceFromPlayers + extraDistance;
            var endDist      = Settings.PlanetaryInstallations.MaximumSpawnDistanceFromPlayers + extraDistance;
            var upDir        = Vector3D.Normalize(startCoords - planetEntity.GetPosition());
            var forwardDir   = Vector3D.Normalize(MyUtils.GetRandomPerpendicularVector(ref upDir));
            var searchMatrix = MatrixD.CreateWorld(startCoords, forwardDir, upDir);

            //Searches in 8 directions from the player position
            var searchDirections = new List <Vector3D>();

            searchDirections.Add(searchMatrix.Forward);
            searchDirections.Add(searchMatrix.Backward);
            searchDirections.Add(searchMatrix.Left);
            searchDirections.Add(searchMatrix.Right);

            if (Settings.PlanetaryInstallations.AggressivePathCheck == true)
            {
                searchDirections.Add(Vector3D.Normalize(searchMatrix.Forward + searchMatrix.Left));
                searchDirections.Add(Vector3D.Normalize(searchMatrix.Forward + searchMatrix.Right));
                searchDirections.Add(Vector3D.Normalize(searchMatrix.Backward + searchMatrix.Left));
                searchDirections.Add(Vector3D.Normalize(searchMatrix.Backward + searchMatrix.Right));
            }

            int debugSpawnPointAttempts = 0;
            int searchDirectionAttempts = 0;

            foreach (var searchDirection in searchDirections)
            {
                searchDirectionAttempts++;
                double searchIncrement = startDist;

                while (searchIncrement < endDist)
                {
                    debugSpawnPointAttempts++;
                    var checkCoords   = searchDirection * searchIncrement + startCoords;
                    var surfaceCoords = SpawnResources.GetNearestSurfacePoint(checkCoords, planet);

                    if (SpawnResources.IsPositionNearEntity(surfaceCoords, Settings.PlanetaryInstallations.MinimumSpawnDistanceFromOtherGrids) == true || SpawnResources.IsPositionInSafeZone(surfaceCoords) == true)
                    {
                        searchIncrement += Settings.PlanetaryInstallations.SearchPathIncrement;
                        continue;
                    }

                    var checkUpDir      = Vector3D.Normalize(surfaceCoords - planetEntity.GetPosition());
                    var checkForwardDir = Vector3D.Normalize(MyUtils.GetRandomPerpendicularVector(ref checkUpDir));
                    var checkMatrix     = MatrixD.CreateWorld(surfaceCoords, checkForwardDir, checkUpDir);

                    var checkDirections = new List <Vector3D>();
                    checkDirections.Add(checkMatrix.Forward);
                    checkDirections.Add(checkMatrix.Backward);
                    checkDirections.Add(checkMatrix.Left);
                    checkDirections.Add(checkMatrix.Right);

                    if (Settings.PlanetaryInstallations.AggressiveTerrainCheck == true)
                    {
                        checkDirections.Add(Vector3D.Normalize(checkMatrix.Forward + checkMatrix.Left));
                        checkDirections.Add(Vector3D.Normalize(checkMatrix.Forward + checkMatrix.Right));
                        checkDirections.Add(Vector3D.Normalize(checkMatrix.Backward + checkMatrix.Left));
                        checkDirections.Add(Vector3D.Normalize(checkMatrix.Backward + checkMatrix.Right));
                    }

                    var  distToCore  = Vector3D.Distance(surfaceCoords, planetEntity.GetPosition());
                    bool badPosition = false;

                    if (spawnGroup.SkipTerrainCheck == false)
                    {
                        foreach (var checkDirection in checkDirections)
                        {
                            double terrainCheckIncrement = 0;

                            while (terrainCheckIncrement < terrainVarianceCheckTarget)
                            {
                                var checkTerrainCoords        = checkDirection * terrainCheckIncrement + surfaceCoords;
                                var checkTerrainSurfaceCoords = SpawnResources.GetNearestSurfacePoint(checkTerrainCoords, planet);
                                var checkDistToCore           = Vector3D.Distance(checkTerrainSurfaceCoords, planetEntity.GetPosition());
                                var elevationDiff             = checkDistToCore - distToCore;

                                if (elevationDiff < Settings.PlanetaryInstallations.MinimumTerrainVariance || elevationDiff > Settings.PlanetaryInstallations.MaximumTerrainVariance)
                                {
                                    badPosition = true;
                                    break;
                                }

                                terrainCheckIncrement += Settings.PlanetaryInstallations.TerrainCheckIncrementDistance;
                            }

                            if (badPosition == true)
                            {
                                break;
                            }
                        }
                    }



                    if (badPosition == false)
                    {
                        spawnCoords = surfaceCoords;
                        Logger.AddMsg("Found Installation Site After: " + debugSpawnPointAttempts.ToString() + " Attempts", true);
                        Logger.AddMsg("Search Directions Used: " + searchDirectionAttempts.ToString(), true);
                        return(true);
                    }

                    searchIncrement += Settings.PlanetaryInstallations.SearchPathIncrement;
                }
            }

            Logger.AddMsg("Could Not Find Installation Site After: " + debugSpawnPointAttempts.ToString() + " Attempts", true);
            return(false);
        }