public static bool CalculateAtmoTravelPath(ImprovedSpawnGroup spawnGroup, Vector3D startCoords, MyPlanet planet, out Vector3D startPathCoords, out Vector3D endPathCoords, out MatrixD startMatrix) { startPathCoords = Vector3D.Zero; endPathCoords = Vector3D.Zero; startMatrix = MatrixD.CreateWorld(Vector3D.Zero, Vector3D.Forward, Vector3D.Up); SpawnResources.RefreshEntityLists(); if (planet == null) { return(false); } var planetEntity = planet as IMyEntity; for (int i = 0; i < Settings.PlanetaryCargoShips.MaxSpawnAttempts; i++) { //Get Starting Point var randDirFromPlayer = SpawnResources.GetRandomCompassDirection(startCoords, planet); var pathDist = SpawnResources.GetRandomPathDist(Settings.PlanetaryCargoShips.MinPathDistanceFromPlayer, Settings.PlanetaryCargoShips.MaxPathDistanceFromPlayer); var midPointSurface = SpawnResources.GetNearestSurfacePoint(randDirFromPlayer * pathDist + startCoords, planet); var upDir = Vector3D.Normalize(midPointSurface - planetEntity.GetPosition()); var altitudeFromMid = SpawnResources.GetRandomPathDist(Settings.PlanetaryCargoShips.MinSpawningAltitude, Settings.PlanetaryCargoShips.MaxSpawningAltitude); var tempStartPath = upDir * altitudeFromMid + midPointSurface; if (spawnGroup.PlanetRequiresAtmo == true && planet.GetAirDensity(tempStartPath) < Settings.PlanetaryCargoShips.MinAirDensity) { tempStartPath = upDir * Settings.PlanetaryCargoShips.MinSpawningAltitude + midPointSurface; if (spawnGroup.PlanetRequiresAtmo == true && planet.GetAirDensity(tempStartPath) < Settings.PlanetaryCargoShips.MinAirDensity) { continue; } } if (SpawnResources.IsPositionNearEntities(tempStartPath, Settings.PlanetaryCargoShips.MinSpawnFromGrids) == true) { continue; } var startCoordsDistFromCenter = Vector3D.Distance(planetEntity.GetPosition(), tempStartPath); //Get Ending Point var randPathDir = SpawnResources.GetRandomCompassDirection(tempStartPath, planet); var randPathDist = SpawnResources.GetRandomPathDist(Settings.PlanetaryCargoShips.MinPathDistance, Settings.PlanetaryCargoShips.MaxPathDistance); var endPathA = randPathDir * randPathDist + tempStartPath; var endPathB = -randPathDir * randPathDist + tempStartPath; var tempEndPath = Vector3D.Zero; if (Vector3D.Distance(endPathA, startCoords) < Vector3D.Distance(endPathB, startCoords)) { tempEndPath = endPathA; } else { tempEndPath = endPathB; randPathDir *= -1; } //TODO: Set At Same Height From Sealevel As Start var endUpDir = Vector3D.Normalize(tempEndPath - planetEntity.GetPosition()); tempEndPath = endUpDir * startCoordsDistFromCenter + planetEntity.GetPosition(); //Check Path var tempMatrix = MatrixD.CreateWorld(tempStartPath, randPathDir, upDir); var truePathDir = Vector3D.Normalize(tempEndPath - tempStartPath); bool badPath = false; foreach (var prefab in spawnGroup.SpawnGroup.Prefabs) { var modifiedStart = Vector3D.Transform((Vector3D)prefab.Position, tempMatrix); double totalSteps = 0; while (totalSteps < randPathDist) { var testPath = totalSteps * truePathDir + modifiedStart; if (SpawnResources.IsPositionInSafeZone(testPath) == true) { badPath = true; break; } if (SpawnResources.GetDistanceFromSurface(testPath, planet) < Settings.PlanetaryCargoShips.MinPathAltitude) { badPath = true; break; } totalSteps += Settings.PlanetaryCargoShips.PathStepCheckDistance; } if (badPath == true) { break; } } if (badPath == true) { continue; } startPathCoords = tempStartPath; endPathCoords = tempEndPath; startMatrix = tempMatrix; return(true); } return(false); }