示例#1
0
        private List <Tracking_Group> SortCelestialBodies()
        {
            List <Tracking_Group> vesselGroups = new List <Tracking_Group>();

            int count = _OrderedBodyList.Count;

            for (int i = 0; i < count; i++)
            {
                Tracking_BodyGroup body = _OrderedBodyList[i];

                List <TrackingStationWidget> bodyVessels = new List <TrackingStationWidget>();

                int vessels = _TrackedVesselWidgets.Count;

                for (int j = 0; j < vessels; j++)
                {
                    if (_TrackedVesselWidgets[j].vessel.mainBody == body.Body)
                    {
                        bodyVessels.Add(_TrackedVesselWidgets[j]);
                    }
                }

                List <Tracking_MoonGroup> moonGroups = new List <Tracking_MoonGroup>();

                int moons = body.Moons.Count;

                for (int k = 0; k < moons; k++)
                {
                    List <TrackingStationWidget> moonVessels = new List <TrackingStationWidget>();

                    for (int l = 0; l < vessels; l++)
                    {
                        if (_TrackedVesselWidgets[l].vessel.mainBody == body.Moons[k])
                        {
                            moonVessels.Add(_TrackedVesselWidgets[l]);
                        }
                    }

                    if (moonVessels.Count > 0)
                    {
                        moonGroups.Add(new Tracking_MoonGroup()
                        {
                            Moon = body.Moons[k], Vessels = SortWidgets(moonVessels)
                        });
                    }
                }

                if (bodyVessels.Count > 0 || moonGroups.Count > 0)
                {
                    vesselGroups.Add(new Tracking_Group(Tracking_Utils.LocalizeBodyName(body.Body.displayName), Tracking_Persistence.GetBodyPersistence(body.Body.flightGlobalsIndex), _instantStart, SortWidgets(bodyVessels), moonGroups, body.Body, VesselType.Unknown, Tracking_Mode.CelestialBody));
                }
            }

            return(vesselGroups);
        }
示例#2
0
        private List <TrackingStationWidget> SortWidgetsBody(List <TrackingStationWidget> widgets, bool asc)
        {
            List <KeyValuePair <TrackingStationWidget, double> > maneuvers = GetManeuvers(widgets);

            List <TrackingStationWidget> sorted = new List <TrackingStationWidget>();

            if (asc)
            {
                for (int i = _OrderedBodyList.Count - 1; i >= 0; i--)
                {
                    Tracking_BodyGroup group = _OrderedBodyList[i];

                    for (int k = group.Moons.Count - 1; k >= 0; k--)
                    {
                        int index = group.Moons[k].flightGlobalsIndex;

                        for (int l = widgets.Count - 1; l >= 0; l--)
                        {
                            if (widgets[l].vessel.mainBody.flightGlobalsIndex == index)
                            {
                                sorted.Add(widgets[l]);
                            }
                        }
                    }

                    for (int j = widgets.Count - 1; j >= 0; j--)
                    {
                        if (widgets[j].vessel.mainBody.flightGlobalsIndex == group.Body.flightGlobalsIndex)
                        {
                            sorted.Add(widgets[j]);
                        }
                    }
                }
            }
            else
            {
                int b = _OrderedBodyList.Count;

                for (int i = 0; i < b; i++)
                {
                    Tracking_BodyGroup group = _OrderedBodyList[i];

                    int m = group.Moons.Count;

                    for (int k = 0; k < m; k++)
                    {
                        int index = group.Moons[k].flightGlobalsIndex;

                        for (int l = widgets.Count - 1; l >= 0; l--)
                        {
                            if (widgets[l].vessel.mainBody.flightGlobalsIndex == index)
                            {
                                sorted.Add(widgets[l]);
                            }
                        }
                    }

                    for (int j = widgets.Count - 1; j >= 0; j--)
                    {
                        if (widgets[j].vessel.mainBody.flightGlobalsIndex == group.Body.flightGlobalsIndex)
                        {
                            sorted.Add(widgets[j]);
                        }
                    }
                }
            }

            int count = maneuvers.Count;

            for (int i = 0; i < count; i++)
            {
                sorted.Add(maneuvers[i].Key);
            }

            return(sorted);
        }
示例#3
0
        private List <Tracking_BodyGroup> OrderBodies()
        {
            var allBodies = FlightGlobals.Bodies.Where(b => b.referenceBody == Planetarium.fetch.Sun && b.referenceBody != b);

            var orderedBodies = allBodies.OrderBy(b => b.orbit.semiMajorAxis).ToList();

            List <Tracking_BodyGroup> bodies = RecursiveCelestialBodies(orderedBodies);

            //for (int i = 0; i < orderedBodies.Count; i++)
            //{
            //    CelestialBody body = orderedBodies[i];

            //    List<CelestialBody> moons = new List<CelestialBody>();

            //    for (int j = 0; j < body.orbitingBodies.Count; j++)
            //    {
            //        CelestialBody moon = body.orbitingBodies[j];

            //        moons.Add(moon);

            //        for (int k = 0; k < moon.orbitingBodies.Count; k++)
            //        {
            //            CelestialBody subMoon = moon.orbitingBodies[k];

            //            moons.Add(subMoon);

            //            for (int l = 0; l < subMoon.orbitingBodies.Count; l++)
            //            {
            //                CelestialBody subSubMoon = subMoon.orbitingBodies[l];

            //                moons.Add(subSubMoon);

            //                for (int m = 0; m < subSubMoon.orbitingBodies.Count; m++)
            //                {
            //                    CelestialBody subSubSubMoon = subSubMoon.orbitingBodies[m];

            //                    moons.Add(subSubSubMoon);

            //                    for (int n = 0; n < subSubSubMoon.orbitingBodies.Count; n++)
            //                    {
            //                        CelestialBody subSubSubSubMoon = subSubSubMoon.orbitingBodies[n];

            //                        moons.Add(subSubSubSubMoon);
            //                    }
            //                }
            //            }
            //        }
            //    }

            //    bodies.Add(new Tracking_BodyGroup() { Body = body, Moons = moons });
            //}

            bool missingHome = true;

            for (int i = bodies.Count - 1; i >= 0; i--)
            {
                if (bodies[i].Body == FlightGlobals.GetHomeBody())
                {
                    missingHome = false;
                    break;
                }
            }

            if (missingHome)
            {
                List <Tracking_BodyGroup> missingHomeBodies = RecursiveCelestialBodies(new List <CelestialBody>()
                {
                    FlightGlobals.GetHomeBody()
                });

                bodies.InsertRange(0, missingHomeBodies);
            }
            else
            {
                for (int i = bodies.Count - 1; i >= 0; i--)
                {
                    Tracking_BodyGroup body = bodies[i];

                    if (body.Body != Planetarium.fetch.Home)
                    {
                        continue;
                    }

                    bodies.RemoveAt(i);
                    bodies.Insert(0, body);
                }
            }

            bodies.Insert(1, new Tracking_BodyGroup()
            {
                Body = Planetarium.fetch.Sun, Moons = new List <CelestialBody>()
            });

            List <Tracking_BodyGroup> ordered = new List <Tracking_BodyGroup>();

            for (int i = 0; i < Tracking_Persistence.BodyOrderList.Count; i++)
            {
                for (int j = bodies.Count - 1; j >= 0; j--)
                {
                    int index = bodies[j].Body.flightGlobalsIndex;

                    if (index != Tracking_Persistence.BodyOrderList[i])
                    {
                        continue;
                    }

                    ordered.Add(bodies[j]);
                    break;
                }
            }

            return(ordered);
        }