public List <APhysicalObject> GenerateStellarCollection(ref StellarSystem stellarSystem, int stellarAmount)
        {
            List <APhysicalObject> stellarList = new List <APhysicalObject>();

            //generate stellarList
            if (_testMode)
            {
                APhysicalObject @object = new Star("Sun", stellarSystem)
                {
                    StarClass          = "G",
                    SizeCode           = 2,
                    SpectralClass      = 5,
                    Luminosity         = 0.1,
                    SurfaceTemperature = 5000,
                    Radius             = 1,
                    Mass = 1,
                };
                stellarSystem.Bodies.Add(@object as ABody);
                stellarList.Add(@object);

                @object = new Star("Nemesis", stellarSystem)
                {
                    StarClass          = "D",
                    SizeCode           = 2,
                    SpectralClass      = 5,
                    Luminosity         = 0.01,
                    SurfaceTemperature = 3000,
                    Radius             = 0.2,
                    Mass = 0.2,
                };
                stellarSystem.Bodies.Add(@object as ABody);
                stellarList.Add(@object);
            }
            else
            {
                for (int i = 0; i < stellarAmount; i++)
                {
                    APhysicalObject @object = GenerateStellarObject(ref stellarSystem);
                    stellarSystem.Bodies.Add(@object as ABody);
                    stellarList.Add(@object);
                }
            }

            stellarList.Sort((x, y) =>
            {
                return(y.Mass.CompareTo(x.Mass));
            });
            return(stellarList);
        }
        public APhysicalObject GenerateStellarObject(ref StellarSystem stellarSystem, int stellarGenerationRand)
        {
            if (_testMode)
            {
                return(GenerateStar(stellarSystem, stellarGenerationRand));
            }
            if (stellarGenerationRand < 100)
            {
                return(GenerateStar(stellarSystem, stellarGenerationRand));
            }
            else
            //Could be B-class stars, giants, neutron stars,protostars, blackholes or other rare stellar objects
            {
                GazCloud gazCloud = new GazCloud()
                {
                    Mass = 4f,
                };

                return(gazCloud);
            }
        }
示例#3
0
 public Star(string name, StellarSystem stellarSystem)
     : base(name, stellarSystem)
 {
 }
示例#4
0
 public Barycenter(string name, StellarSystem stellarSystem)
     : base(name, stellarSystem)
 {
 }
        public StellarSystem GetStellarSystem(int starCount)
        {
            if (_testMode)
            {
                starCount = 2;
            }

            StellarSystem stellarSystem = new StellarSystem();

            //generate a collection of StarLike Objects ordered by mass
            List <APhysicalObject> stellarCollection;

            if (starCount == 0)
            {
                stellarCollection = GenerateStellarCollection(ref stellarSystem);
            }
            else
            {
                stellarCollection = GenerateStellarCollection(ref stellarSystem, starCount);
            }

            //system age (the smallest)
            double systemAge = double.MaxValue;

            foreach (APhysicalObject stellarObject in stellarCollection)
            {
                if (stellarObject is Star star)
                {
                    if (star.Age < systemAge)
                    {
                        systemAge = star.Age;
                    }
                }
            }
            stellarSystem.SystemAge = systemAge;


            //TODO : set age modification for each stars based from table

            //determining abudance factor
            int abudance         = randomSource.Next(1, 20) + (int)systemAge;
            int abudanceModifier = 0;

            if (3 <= abudance && abudance <= 9)
            {
                abudanceModifier = 2;
            }
            else if (10 <= abudance && abudance <= 12)
            {
                abudanceModifier = 1;
            }
            else if (13 <= abudance && abudance <= 18)
            {
                abudanceModifier = 0;
            }
            else if (19 <= abudance && abudance <= 21)
            {
                abudanceModifier = -1;
            }
            else if (21 <= abudance)
            {
                abudanceModifier = -3;
            }

            //Building Orbits

            //ring orbits, as substitute
            for (int i = 1; i < stellarCollection.Count; i++)
            {
                Orbit orbit = ForgeOrbit(stellarCollection[0], stellarCollection[i], systemAge);
                stellarSystem.Orbits.Add(orbit);
            }

            //WARNING : EXTREMLY NOT DRY ! Algorithmic solution needed

            /*
             * //By Convention name are A,B,C... in the decreasing mass order
             * if(stellarCollection.Count ==2)
             * {
             *  //B orbiting A
             *  Orbit orbit = ForgeOrbit(stellarCollection[0], stellarCollection[1], systemAge);
             *  stellarSystem.Orbits.Add(orbit);
             * }
             * else if (stellarCollection.Count == 3)
             * {
             *  //triple case for C : around A, around B, Around AB
             *
             *  APhysicalObject A = stellarCollection[0];
             *  APhysicalObject B = stellarCollection[1];
             *  APhysicalObject C = stellarCollection[2];
             *
             *  int dice = randomSource.Next(0,2);
             *  if (dice==0)
             *  {
             *      //Create AB
             *      Orbit orbit = ForgeOrbit(stellarCollection[0], stellarCollection[1], systemAge);
             *      stellarSystem.Orbits.Add(orbit);
             *
             *      // around A
             *      Orbit orbit2 = ForgeOrbit(stellarCollection[0], stellarCollection[2], systemAge);
             *      stellarSystem.Orbits.Add(orbit2);
             *
             *  } //around B
             *  else if (dice == 1)
             *  {
             *      //Create AB
             *      Orbit orbit = ForgeOrbit(stellarCollection[0], stellarCollection[1], systemAge);
             *      stellarSystem.Orbits.Add(orbit);
             *
             *      // around A
             *      Orbit orbit2 = ForgeOrbit(stellarCollection[1], stellarCollection[2], systemAge);
             *      stellarSystem.Orbits.Add(orbit2);
             *  }
             *  else //Around AB
             *  {
             *      //Create AB
             *
             *      //forge barycentric orbit between A,B and a barycenter
             *      //forge orbit of C around barycenter
             *
             *      //Orbit orbit = ForgeOrbit(stellarCollection[0], stellarCollection[1], systemAge);
             *      //stellarSystem.Orbits.Add(orbit);
             *  }
             *
             * }
             * else if (stellarCollection.Count == 4)
             * {
             *  //4 case for D :around A, around AB with C,  Around ABC
             * }
             * else if (stellarCollection.Count == 5)
             * {
             *  //3 case for D : around AB and CD,  Around AB , around CD
             * }
             * else if (stellarCollection.Count == 6)
             * {
             *  //3 case for D : around AB and CD,  Around AB , around CD
             * }
             * else
             * {
             *  //orbit on rings
             * }
             */

            stellarSystem.PhysicalObjectRoot = stellarCollection[0];
            //set the age limitation factor

            //

            return(stellarSystem);
        }
        public Star GenerateStar(StellarSystem stellarSystem, int starGenerationRand)
        {
            //star generation
            Star star;

            string starClass = "";
            int    sizeCode  = 0;

            int giantSize = randomSource.Next(1, 10) >= 7 ? 4 : 5;

            //manque O et B classes : case 0
            if (starGenerationRand == 1)
            {
                starClass = "A";
                sizeCode  = giantSize;
            }
            if (2 <= starGenerationRand && starGenerationRand <= 4)
            {
                starClass = "F";
                sizeCode  = giantSize;
            }
            if (5 <= starGenerationRand && starGenerationRand <= 12)
            {
                starClass = "G";
                sizeCode  = giantSize;
            }
            if (13 <= starGenerationRand && starGenerationRand <= 26)
            {
                starClass = "K";
                sizeCode  = 5;
            }
            if (27 <= starGenerationRand && starGenerationRand <= 36)//white dwarf, D for Degenerate
            {
                starClass = "D";
                sizeCode  = 7;
            }
            if (37 <= starGenerationRand && starGenerationRand <= 85)
            {
                starClass = "M";
                sizeCode  = 5;
            }
            if (86 <= starGenerationRand && starGenerationRand <= 98)//brown dwarf LTY
            {
                starClass = "L";
            }
            if (starGenerationRand == 99)//Giants
            {
                int giantRand = randomSource.Next(1, 10);
                if (giantRand == 1)
                {
                    starClass = "F"; sizeCode = 3;
                }
                if (giantRand == 2)
                {
                    starClass = "G"; sizeCode = 3;
                }
                if (3 <= giantRand && giantRand <= 7)
                {
                    starClass = "F"; sizeCode = 3;
                }
                if (giantRand > 8)
                {
                    starClass = "K"; sizeCode = 4;
                }
            }

            //define spectralClass
            int spectralClass = (starClass == "K" && sizeCode == 4) ? 0 : randomSource.Next(0, 9);

            //White/Brown Dwarf case
            int dwarfGenerationRand = randomSource.Next(1, 10);

            if (starClass == "D" || starClass == "L")
            {
                star = new Star("unnamed", stellarSystem)
                {
                    StarClass     = starClass,
                    SizeCode      = 0,
                    SpectralClass = spectralClass
                };
            }
            else
            {
                //match from the table
                BasicStar basicStar = _basicStar.Find(
                    x => x.StarType == starClass &&
                    x.SizeCode == sizeCode &&
                    x.Random == spectralClass
                    );
                star = new Star("unnamed", stellarSystem)
                {
                    StarClass          = starClass,
                    SizeCode           = sizeCode,
                    SpectralClass      = spectralClass,
                    Luminosity         = basicStar.Luminosity,
                    SurfaceTemperature = basicStar.SurfaceTemperature,
                    Radius             = basicStar.Radius,
                    Mass = basicStar.Mass,
                };
            }


            //Flares Star M3 to M9  1D10*50% periodicaly
            //TODO

            //subGiant randomisation
            if (sizeCode == 4)
            {
                int   subGiantRand = randomSource.Next(1, 10);
                float rate         = 0;
                switch (subGiantRand)
                {
                case 3: rate = -0.1f; break;

                case 4: rate = -0.2f; break;

                case 5: rate = -0.3f; break;

                case 6: rate = -0.4f; break;

                case 7: rate = 0.1f; break;

                case 8: rate = 0.2f; break;

                case 9: rate = 0.3f; break;

                case 10: rate = 0.4f; break;

                default: rate = 0; break;
                }
                star.Mass       += star.Mass * rate;
                star.Luminosity += star.Luminosity * rate * 2;
                star.Radius      = (float)Math.Pow(star.Luminosity, 0.5 * (5800 / star.SurfaceTemperature) * (5800 / star.SurfaceTemperature));
            }

            //age
            int ageRandom = randomSource.Next(1, 10);

            //from table
            StarAge starAge = _systemAgeSource
                              .FindAll(x =>
                                       x.StarClass == starClass &&
                                       x.SpectralClassMin <= star.SpectralClass &&
                                       star.SpectralClass <= x.SpectralClassMax)
                              .Find(x => x.Random == ageRandom);

            star.Age      = starAge.Age;
            star.LifeSpan = starAge.LifeSpan;

            //giant case & subgiant case
            if (sizeCode == 4 || sizeCode == 3)
            {
                star.Age      = 10 * star.Mass / star.Luminosity;
                star.Age     += star.Age * ((sizeCode == 4)? 0.1f : 0.2f);
                star.LifeSpan = star.Age;
            }

            //calculating temperature and luminosity of dwarves with age modifiers
            if (starClass == "L" || starClass == "D")
            {
                star.LifeSpan = float.MaxValue;
                DwarfStar dwarfData =
                    (starClass == "D")?
                    _whitedwarfs.Find(x => x.Random == dwarfGenerationRand)
                    : _browndwarfs.Find(x => x.Random == dwarfGenerationRand);

                star.Mass           = dwarfData.Mass;
                star.Radius         = dwarfData.Radius;
                dwarfGenerationRand = Physic.Clamp(dwarfGenerationRand + starAge.TemperatureRollModifier, 1, 10);
                dwarfData           =
                    (starClass == "D") ?
                    _whitedwarfs.Find(x => x.Random == dwarfGenerationRand)
                    : _browndwarfs.Find(x => x.Random == dwarfGenerationRand);

                star.SurfaceTemperature = dwarfData.Temperature;

                star.Luminosity = Math.Pow(star.Radius, 2) * Math.Pow(star.SurfaceTemperature, 4) / Math.Pow(5800, 4);
            }

            star.Luminosity += star.Luminosity * starAge.LuminosityModifier;

            return(star ?? throw new InvalidOperationException());
        }
 public List <APhysicalObject> GenerateStellarCollection(ref StellarSystem stellarSystem)
 {
     return(GenerateStellarCollection(ref stellarSystem, StarCount()));
 }
 public APhysicalObject GenerateStellarObject(ref StellarSystem stellar)
 {
     //define star class
     return(GenerateStellarObject(ref stellar, randomSource.Next(1, 100)));
 }
示例#9
0
 public Planet(string name, StellarSystem stellarSystem)
     : base(name, stellarSystem)
 {
 }