상속: CourseUtils
예제 #1
0
        public FlightPlan Clone()
        {
            var result = new FlightPlan();

            result.name = String.Copy(name);
            result.description = String.Copy(description);
            result.planet = planet;

            WayPoint prev_wp = null;

            foreach (var wp in course)
            {
                var new_wp = wp.Clone();

                if (prev_wp != null)
                    prev_wp.next = new_wp;

                result.course.Add(new_wp);

                prev_wp = new_wp;
            }

            Deb.Log("FlightPlan.Clone: update waypoint values for resulting course.");
            result.UpdateWayPointValues(planet);

            return result;
        }
예제 #2
0
        private void LoadPlansFromNode(ConfigNode node)
        {
            foreach (ConfigNode listNode in node.nodes)
            {
                Deb.Log("LoadPlansFromNode: list node {0}", listNode.name);

                var planet_name = listNode.name;

                List<FlightPlan> fplist = null;

                if (flightPlansDict.TryGetValue(planet_name, out fplist))
                {
                    Deb.Log("LoadPlansFromNode: fplist for planet {0} already exists.", planet_name);
                }
                else
                {
                    Deb.Log("LoadPlansFromNode: create fplist for planet {0}.", planet_name);
                    fplist = new List<FlightPlan>();
                    flightPlansDict[planet_name] = fplist;
                }

                foreach (ConfigNode fpNode in listNode.nodes)
                {
                    FlightPlan fp = new FlightPlan();

                    fp.SetFromConfigNode(fpNode);

                    int existing_index = fplist.FindIndex(afp => (fp.name == afp.name));

                    if (existing_index < 0)
                    {
                        Deb.Log("LoadPlansFromNode: new flight plan named {0}.", fp.name);
                        fplist.Add(fp);
                    }
                    else
                    {
                        Deb.Log("LoadPlansFromNode: existing flight plan named {0} will be overwritten.", fp.name);
                        fplist[existing_index] = fp;
                    }
                }
            }
        }
예제 #3
0
        public void SavePlan(FlightPlan plan)
        {
            if (plan.planet == null)
            {
                Deb.Err("SavePlan: plan has no planet");
                return;
            }

            if (plan.name == currentName)
            {
                Deb.Log("SavePlan: same name, overwrite current");
                plan.description = currentDesc;
            }
            else
            {
                current = plan.Clone();
                current.name = currentName;
                current.description = currentDesc;
                plan = current;
            }

            flightPlan = current;

            List<FlightPlan> plans_for_planet = null;

            if (!flightPlansDict.TryGetValue(planet.name, out plans_for_planet))
            {
                Deb.Log("SavePlan: creating new plan list for planet {0}", planet.name);
                plans_for_planet = new List<FlightPlan>();
                flightPlansDict[planet.name] = plans_for_planet;
            }

            bool plan_present = false;

            foreach (var pplan in plans_for_planet)
            {
                if (System.Object.ReferenceEquals(plan, pplan))
                {
                    plan_present = true;
                    break;
                }
            }

            if (!plan_present)
            {
                Deb.Log("SavePlan: plan not present, create one in list");
                plans_for_planet.Add(plan);
            }

            ConfigNode rootNode = new ConfigNode();

            ConfigNode node = rootNode.AddNode(flightPlansNodeName);

            // plan_list will be key/value pair
            foreach (var pair in flightPlansDict)
            {
                ConfigNode listNode = node.AddNode(pair.Key);

                foreach (var aplan in pair.Value)
                {
                    listNode.AddNode(aplan.ToConfigNode());
                }
            }

            rootNode.Save(GetFlightPlanURI());
        }
예제 #4
0
        public void UpdateFlightPlans(George george, Vessel vessel)
        {
            if (vessel == null)
            {
                current = null;
                plans.Clear();
                planet = null;
            }
            else
            {
                if (!System.Object.ReferenceEquals(current, george.flightPlan))
                {
                    current = george.flightPlan;
                    currentName = String.Copy(current.name);
                    currentDesc = String.Copy(current.description);
                }

                if (planet != vessel.mainBody || plans == null)
                {
                    planet = vessel.mainBody;

                    if (planet != null)
                    {
                        if (flightPlansDict.TryGetValue(planet.name, out plans))
                        {
                            Deb.Log("UpdateFlightPlans: got plans for planet {0}", planet.name);
                        }
                    }
                    else
                    {
                        plans = null;
                    }
                }
            }
        }
예제 #5
0
        public void ApplyPlan(FlightPlan plan)
        {
            flightPlan = plan.Clone();
            current = plan;
            currentName = String.Copy(current.name);
            currentDesc = String.Copy(current.description);

            flightPlan.Activate(this, vessel, vesselData);
        }