Exemple #1
0
        public static void MovePlanet(PlanetDefinition planet, string targetSystem)
        {
            if (StarSystem.CBDict.ContainsKey(planet.Name))
            {
                CelestialBody planetCB = StarSystem.CBDict[planet.Name];

                string parent_name;

                try
                {
                    parent_name = planetCB.GetOrbit().referenceBody.GetName();
                    if (parent_name.StartsWith("Black"))  //DANGER: HACK
                    {
                        parent_name = "Sun";
                    }
                }
                catch (Exception)
                {
                    parent_name = "Sun";
                }

                Debug.Log("moving Planet " + planet.Name + " from: " + parent_name + " to " + targetSystem);

                if (StarSystem.CBDict[parent_name].orbitingBodies.Contains(planetCB))
                {
                    if (StarSystem.CBDict.ContainsKey(targetSystem))
                    {
                        StarSystem.CBDict[targetSystem].orbitingBodies.Add(planetCB);
                        StarSystem.CBDict[parent_name].orbitingBodies.Remove(planetCB);

                        if (planet.orbit != null) // we have a new orbit specification for this dude.
                        {
                            planetCB.orbitDriver.orbit = planet.orbit.getOrbit(StarSystem.CBDict[targetSystem]);
                        }

                        planetCB.orbitDriver.referenceBody = StarSystem.CBDict[targetSystem];
                        planetCB.orbitDriver.UpdateOrbit();
                        StarSystem.CBDict[parent_name].CBUpdate();
                        StarSystem.CBDict[targetSystem].CBUpdate();
                        Debug.Log(planet.Name + " moved to " + targetSystem);
                    }
                    else
                    {
                        Debug.Log("Could not find CelestialBody " + targetSystem);
                    }
                }
                else
                {
                    Debug.Log("Couldn't find " + planet.Name + " in " + parent_name + "'s orbit. Was it moved already?");
                }
            }
            else
            {
                Debug.Log("Planet " + planet.Name + " does not exist!");
            }
        }
Exemple #2
0
        List <StarSystemDefintion> getStars(ConfigNode[] stars_config)
        {
            List <StarSystemDefintion> returnValue = new List <StarSystemDefintion>();

            //Grab star info
            foreach (var star in stars_config)
            {
                if (IsStarValid(star))
                {
                    var sun = star.GetNode("Sun");
                    StarSystemDefintion starSystemDefintion = new StarSystemDefintion();

                    starSystemDefintion.Name = sun.GetNode("CelestialBody").GetValue("name");
                    starSystemDefintion.FlightGlobalsIndex  = int.Parse(sun.GetNode("CelestialBody").GetValue("flightGlobalIndex"));
                    starSystemDefintion.orbit.SemiMajorAxis = double.Parse(sun.GetNode("Orbit").GetValue("semiMajorAxis"));
                    try
                    {
                        starSystemDefintion.BodyDescription = sun.GetNode("CelestialBody").GetValue("BodyDescription");
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        starSystemDefintion.Radius = double.Parse(sun.GetNode("CelestialBody").GetValue("Radius"));
                    }
                    catch (Exception)
                    {
                        starSystemDefintion.Radius = 261600000;
                    }
                    try
                    {
                        string color = sun.GetNode("CelestialBody").GetValue("StarColor");
                        Debug.Log("Setting " + star.name + "'s color to " + color);
                        starSystemDefintion.StarColor = (StarSystem.StarColors.ContainsKey(color)) ? StarSystem.StarColors[color] : null;
                    }
                    catch (Exception e)
                    {
                        Debug.Log("failed to set color " + e);
                        starSystemDefintion.StarColor = null;
                    }
                    try
                    {
                        starSystemDefintion.Mass = double.Parse(sun.GetNode("CelestialBody").GetValue("Mass"));
                    }
                    catch (Exception)
                    {
                        starSystemDefintion.Mass = 1.7565670E28;
                    }
                    try
                    {
                        starSystemDefintion.ScienceMultiplier =
                            float.Parse(sun.GetNode("CelestialBody").GetValue("ScienceMultiplier"));
                    }
                    catch (Exception)
                    {
                        starSystemDefintion.ScienceMultiplier = 10f;
                    }

                    if (sun.GetNode("Orbit") != null)
                    {
                        starSystemDefintion.orbit.loadConfig(sun.GetNode("Orbit"));
                    }
                    else
                    {
                        starSystemDefintion.orbit = null;
                    }

                    //Planets
                    foreach (ConfigNode planet in star.GetNodes("Planet"))
                    {
                        PlanetDefinition planetDef = new PlanetDefinition();
                        planetDef.Name = planet.GetValue("name");
                        if (planetDef.Name != null)
                        {
                            if (planet.GetNode("Orbit") != null)
                            {
                                planetDef.orbit.loadConfig(planet.GetNode("Orbit"));
                            }
                            else
                            {
                                planetDef.orbit = null;
                                Debug.Log(planetDef.Name + " in " + starSystemDefintion.Name + " is missing orbit information, using original");
                            }

                            starSystemDefintion.orbitingBodies.Add(planetDef);
                        }
                        else
                        {
                            Debug.Log("A planet in " + starSystemDefintion.Name + " is missing it's name!");
                        }
                    }

                    returnValue.Add(starSystemDefintion);
                }
                else
                {
                    Debug.Log("Star Unable be create lack requirement fields: CelestialBody/name,CelestialBody/flightGlobalIndex,Orbit/semiMajorAxis");
                    continue;
                }
            }
            return(returnValue);
        }