public void getmoons()
{
// Not in flight, assume Kerbin
if (!HighLogic.LoadedSceneIsFlight)
{
// Find Kerbin
List<CelestialBody> all = new List<CelestialBody>(Sun.orbitingBodies);
foreach (CelestialBody body in all)
{
if (body.name == "Kerbin")
{
moons = new List<CelestialBody>(body.orbitingBodies);
break;
}
}
}
// In interstellar space
else if (FlightGlobals.ActiveVessel.mainBody == Sun)
{
if (moons != null)
{
moons.Clear();
}
else
{
moons = new List<CelestialBody>();
}
}
// Orbiting a planet
else if (FlightGlobals.ActiveVessel.mainBody.referenceBody == Planetarium.fetch.Sun)
{
moons = new List<CelestialBody>(FlightGlobals.ActiveVessel.mainBody.orbitingBodies);
}
// Orbiting a moon, gets all moons in planetary system
else
{
moons = new List<CelestialBody>();
List<CelestialBody> allmoons = new List<CelestialBody>(FlightGlobals.ActiveVessel.mainBody.referenceBody.orbitingBodies);
foreach (CelestialBody moon in allmoons)
{
if (FlightGlobals.ActiveVessel.mainBody != moon)
{
moons.Add(moon);
}
}
}
}