Skip to content

Commit

Permalink
Import the stock launch sites
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Aug 15, 2020
1 parent a0191fa commit ba1e8fa
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions MechJeb2/MechJebModuleLandingGuidance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,17 @@ private void InitLandingSitesList()

if (launchSiteName == null || lat == null || lon == null)
{
print("Ignore langing site with null value");
print("Ignore landing site with null value");
continue;
}

double latitude, longitude;
double.TryParse(lat, out latitude);
double.TryParse(lon, out longitude);
double.TryParse(lat, out double latitude);
double.TryParse(lon, out double longitude);

string bodyName = site.GetValue("body");
CelestialBody body = bodyName != null ? FlightGlobals.Bodies.Find(b => b.bodyName == bodyName) : Planetarium.fetch.Home;

if (!landingSites.Any(p => p.name == launchSiteName))
if (landingSites.All(p => p.name != launchSiteName))
{
print("Adding " + launchSiteName);
landingSites.Add(new LandingSite()
Expand All @@ -283,7 +282,23 @@ private void InitLandingSitesList()
}
}
}


// Import KSP launch sites
foreach (LaunchSite site in PSystemSetup.Instance.LaunchSites)
{
if (site.spawnPoints.Length > 0)
{
LaunchSite.SpawnPoint point = site.spawnPoints[0];
landingSites.Add(new LandingSite()
{
name = point.name.Replace("_", " "),
latitude = point.latitude,
longitude = point.longitude,
body = site.Body
});
}
}

// Import KerbTown/Kerbal-Konstructs launch site
foreach (var config in GameDatabase.Instance.GetConfigs("STATIC"))
{
Expand All @@ -306,7 +321,7 @@ private void InitLandingSitesList()
double latitude = Math.Asin(pos.y) * UtilMath.Rad2Deg;
double longitude = Math.Atan2(pos.z, pos.x) * UtilMath.Rad2Deg;

if (body != null && !landingSites.Any(p => p.name == launchSiteName))
if (body != null && landingSites.All(p => p.name != launchSiteName))
{
landingSites.Add(new LandingSite()
{
Expand Down Expand Up @@ -347,7 +362,7 @@ private void InitLandingSitesList()
double.TryParse(lat, out latitude);
double.TryParse(lon, out longitude);

if (!landingSites.Any(p => p.name == launchSiteName))
if (landingSites.All(p => p.name != launchSiteName))
{
landingSites.Add(new LandingSite()
{
Expand Down

0 comments on commit ba1e8fa

Please sign in to comment.