示例#1
0
        public StarSystem Create(string name)
        {
            //create the starsystem
            var starSystem = new StarSystem(name);

            _starFactory.Create(name).ForEach(star =>
            {
                star.StarSystem = starSystem;
                starSystem.Stars.Add(star);
            });

            // Create some working Vars:
            double inner = 0.0;
            double outer = 0.0;

            for (var i = 0; i < starSystem.Stars.Count; i++)
            {
                var star      = starSystem.Stars[i];
                var protoStar = new ProtoStar(star);

                for (int j = 0; j < starSystem.Stars.Count; j++)
                {
                    if (i != j)
                    {
                        var starB = starSystem.Stars[j];
                        // Forbidden zone inner is 1/3 of the minimum seperation
                        // Forbidden zone outer is 3x the maximum seperation
                        // TODO: Add in effect of eccentricities
                        double minseperation, maxseperation;
                        if (star.SemiMajorAxis > starB.SemiMajorAxis)
                        {
                            // Orbits beyond other star
                            minseperation = Math.Abs(star.SemiMajorAxis * (1.0 - star.Eccentricity) - starB.SemiMajorAxis * (1.0 + starB.Eccentricity));
                            if (i == 0)
                            {
                                maxseperation = Math.Abs(star.SemiMajorAxis * (1.0 + star.Eccentricity) - starB.SemiMajorAxis * (1.0 - starB.Eccentricity));
                            }
                            else
                            {
                                maxseperation = 200;
                            }
                        }
                        else
                        {
                            // Orbits inside other star
                            minseperation = Math.Abs(star.SemiMajorAxis * (1.0 + star.Eccentricity) - starB.SemiMajorAxis * (1.0 - starB.Eccentricity));
                            if (i == 0)
                            {
                                maxseperation = Math.Abs(star.SemiMajorAxis * (1.0 - star.Eccentricity) - starB.SemiMajorAxis * (1.0 + starB.Eccentricity));
                            }
                            else
                            {
                                maxseperation = 200;
                            }
                        }

                        /*minseperation = Math.Abs(starSystem.Stars[j].SemiMajorAxis - starSystem.Stars[i].SemiMajorAxis);
                         * double maxseperation;
                         * if (i == 0)
                         *  maxseperation = Math.Abs(starSystem.Stars[j].SemiMajorAxis + starSystem.Stars[i].SemiMajorAxis);
                         * else
                         *  maxseperation = 200;*/
                        inner = minseperation / 3.0;
                        outer = maxseperation * 3.0;
                        protoStar.UpdateDust(inner, outer, false);
                    }
                    initOrbitPosition(star);
                }

                //protoStar.DistributePlanetaryMasses(rnd);
                int counter = 0;
                while (protoStar.DustAvailable)
                {
                    counter++;
                    var protoPlanet = new ProtoPlanet(protoStar.Star, protoStar.Star)
                    {
                        Star          = star,
                        SemiMajorAxis = rnd.NextDouble(protoStar.PlanetInnerBound, protoStar.PlanetOuterBound),
                        Eccentricity  = rnd.RandomEccentricity(),
                        //Eccentricity = 0.99,
                        DustMass = Constants.Stargen.PROTOPLANET_MASS,
                    };
                    protoPlanet.init();


                    if (protoStar.IsDustAvailable(protoPlanet))
                    {
                        //var criticalMass = protoPlanet.CriticalLimit;
                        AccreteDust(protoStar, protoPlanet);

                        if (protoPlanet.Mass > Constants.Stargen.PROTOPLANET_MASS)
                        {
                            CoalescePlanetesimals(protoStar, protoPlanet);
                        }
                        else
                        {
#if LOG4NET_ENABLED
                            logger.Debug("Planet at " + protoPlanet.SemiMajorAxis + " failed due to large neighbor!");
#endif
                        }
                    }
                    if (counter == 10000)
                    {
#if LOG4NET_ENABLED
                        logger.Debug("Exceeded 10000 attempts to create a planet! Will not continue!");
#endif
                    }
                }
                while (protoStar.DustAvailable && counter < 10000)
                {
                    ;
                }

                //populate the Star from the protoStar
                protoStar.Planets.ForEach(planet =>
                {
                    planet.Planet.Primary = star;
                    if (_generateMoons)
                    {
                        DistMoonMasses(protoStar, planet);
                    }
                    star.Planets.Add(planet.Planet);
                });
                star.Planets = new BindingList <Planet>(star.Planets.OrderBy(x => x.SemiMajorAxis).ToList());
                GeneratePlanets(star);
            }

            return(starSystem);
        }