예제 #1
0
        public string OrbitPatcher(Body body)
        {
            // This if is here to make sure stars don't give us trouble
            if (body.generatedBody.orbitDriver.orbit.referenceBody == null)
                body.generatedBody.orbitDriver.orbit.referenceBody = ListOfBodies.Find(rb => rb.name == body.orbit.referenceBody).generatedBody.celestialBody;

            if (!body.generatedBody.celestialBody.Has("sbPatched") && body.generatedBody.celestialBody.Has("orbitPatches"))
            {
                ConfigNode patch = new ConfigNode();
                if (body.generatedBody.celestialBody.orbit != null)
                {
                    OrbitLoader loader = new OrbitLoader();
                    patch.AddData(body.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches"));

                    Parser.LoadObjectFromConfigurationNode(loader, patch);
                    body.generatedBody.orbitDriver.orbit = new Orbit(loader.orbit);
                }
                // This "else" is here to make sure stars don't give us trouble
                else
                {
                    OrbitLoader loader = new OrbitLoader();
                    loader.orbit = new Orbit();
                    loader.orbit.referenceBody = body.generatedBody.orbitDriver.orbit.referenceBody;
                    patch.AddData(body.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches"));

                    Parser.LoadObjectFromConfigurationNode(loader, patch);
                    if (!patch.HasValue("inclination")) loader.orbit.inclination = 0;
                    if (!patch.HasValue("eccentricity")) loader.orbit.eccentricity = 0;
                    if (!patch.HasValue("semiMajorAxis")) loader.orbit.semiMajorAxis = 0;
                    if (!patch.HasValue("longitudeOfAscendingNode")) loader.orbit.LAN = 0;
                    if (!patch.HasValue("argumentOfPeriapsis")) loader.orbit.argumentOfPeriapsis = 0;
                    if (!patch.HasValue("meanAnomalyAtEpoch") && !patch.HasValue("meanAnomalyAtEpochD")) loader.orbit.meanAnomalyAtEpoch = 0;
                    if (!patch.HasValue("epoch")) loader.orbit.epoch = 0;

                    body.generatedBody.orbitDriver.orbit = new Orbit(loader.orbit);
                }

                body.generatedBody.celestialBody.Set("orbitPatches", new ConfigNode());

                if (patch.GetValue("referenceBody") != null)
                    body.orbit.referenceBody = patch.GetValue("referenceBody");

                if (patch.GetValue("referenceBody") != null && body.name == "Kerbin")
                {
                    // Keep the ConfigNode for Kerbin's referenceBody in case Kerbin is the sbSecondary
                    ConfigNode temp = body.generatedBody.celestialBody.Get<ConfigNode>("orbitPatches");
                    temp.AddValue("referenceBody", patch.GetValue("referenceBody"));
                    body.generatedBody.celestialBody.Set("orbitPatches", temp);
                    body.generatedBody.celestialBody.Set("sbPatched", true);
                }
                else
                {
                    body.generatedBody.celestialBody.Set("orbitPatches", new ConfigNode());
                }

                // Fix sphereOfInfluence
                if (!body.generatedBody.celestialBody.Has("sphereOfInfluence"))
                    body.generatedBody.celestialBody.sphereOfInfluence = body.generatedBody.orbitDriver.orbit.semiMajorAxis * Math.Pow(body.generatedBody.celestialBody.Mass / ListOfBodies.Find(rb => rb.name == body.orbit.referenceBody).generatedBody.celestialBody.Mass, 0.4);

            }
            return body.orbit.referenceBody;
        }