Exemple #1
0
        /// <summary>
        ///    Constructs new StarSystem instance from given data and adds it into world.
        /// </summary>
        public StarSystem(WorldContext worldContext, StarSystemData data)
        {
            WorldContext = worldContext;

            ID = data.ID;
            UniverseMapPosition = data.UniverseMapPosition;
            worldContext.StarSystems.Add(this);
        }
        public static WorldContext GenerateWorld(ShipData playerShipData)
        {
            const Int32 starSystemsCount = 16;
            var         positions        = GenerateStarSystemsPositions(starSystemsCount, 10);

            var starSystemsData = new StarSystemsData {
                StarSystems = new StarSystemData[starSystemsCount]
            };
            var spaceObjects = new List <SpaceObjectData>();

            for (Int32 i = 0; i < starSystemsCount; i++)
            {
                var starSystem = new StarSystemData
                {
                    ID = Guid.NewGuid(),
                    UniverseMapPosition = positions[i]
                };

                starSystemsData.StarSystems[i] = starSystem;

                var star = GenerateStar(starSystem);
                spaceObjects.Add(star);
                spaceObjects.AddRange(GeneratePlanetsSystem(star));
            }

            spaceObjects.Add(playerShipData);
            playerShipData.LocationID = starSystemsData.StarSystems.First().ID;

            var captainsData = new CaptainsData
            {
                PlayerData = new CaptainData
                {
                    CurrentShipID = playerShipData.ID
                }
            };

            var worldContext = new WorldContext(new WorldContextData
            {
                WorldCtlData = new WorldCtlData {
                    Date = new DateTime(3042, 1, 1)
                },
                StarSystemsData  = starSystemsData,
                SpaceObjectsData = new SpaceObjectsData {
                    SpaceObjects = spaceObjects.ToArray()
                },
                CaptainsData = captainsData
            });

            return(worldContext);
        }
        private static StarData GenerateStar(StarSystemData starSystemData)
        {
            //Пока генерируем только главную последовательность
            Single mass        = Mathf.Pow(Random.Range(0.54f, 1.3f), 2f) * Constants.SolMass;
            var    type        = StarType.Yellow;
            Single surfaceTemp = -1f;
            {
                if (mass >= 0.3 * Constants.SolMass && mass <= 0.8 * Constants.SolMass)                 //M, красный карлик
                {
                    type        = StarType.Red;
                    surfaceTemp = Random.Range(2000f, 5000f);
                }
                else if (mass > 0.8 * Constants.SolMass && mass <= 1.7 * Constants.SolMass)                 //Типа солнца
                {
                    type        = StarType.Yellow;
                    surfaceTemp = Random.Range(3500f, 7500f);
                }
                else if (mass > 1.7 * Constants.SolMass && mass <= 18 * Constants.SolMass)                 //Белая или полуголубая звезда
                {
                    type        = StarType.White;
                    surfaceTemp = Random.Range(6000f, 30000f);
                }
                else if (mass > 18 * Constants.SolMass)                 //Почти гигант, голубая звезда
                {
                    type        = StarType.Blue;
                    surfaceTemp = Random.Range(10000f, 60000f);
                }
            }

            String name = type + " starData";

            Single luminosity = Mathf.Pow(mass / Constants.SolMass, 3.9f) * Constants.SolLuminosity;

            Single radius = Mathf.Sqrt(luminosity) * Constants.SolRadius * (Constants.SolTemperature * Constants.SolTemperature)
                            / (surfaceTemp * surfaceTemp * Mathf.Sqrt(Constants.SolLuminosity));                                      //L=(R^2)*(T^4)

            return(new StarData
            {
                LocationID = starSystemData.ID,
                Mass = mass,
                Name = name,
                Type = type,
                Radius = radius,
                SurfaceTemperature = surfaceTemp,
                Luminosity = luminosity
            });
        }