Пример #1
0
        /// <summary>
        /// Creates an test system with planets of varying longitude of periapsis.
        /// Adds to game.StarSystem.
        /// </summary>
        public StarSystem CreateLongitudeTest(Game game)
        {
            StarSystem system = new StarSystem(game, "Longitude test", -1);

            Entity sun = _starFactory.CreateStar(system, GameConstants.Units.SolarMassInKG, GameConstants.Units.SolarRadiusInAu, 4.6E9, "G", 5778, 1, SpectralType.G, "_lop");

            MassVolumeDB sunMVDB = sun.GetDataBlob <MassVolumeDB>();

            double planetSemiMajAxis  = 0.387098;
            double planetEccentricity = 0.9;// 0.205630;
            double planetInclination  = 0;
            double planetLoAN         = 48.33167;
            double planetLoP          = 77.45645;
            double planetMeanLongd    = 252.25084;


            for (int i = 0; i < 13; i++)
            {
                NameDB           planetNameDB = new NameDB("planet" + i);
                SystemBodyInfoDB planetBodyDB = new SystemBodyInfoDB {
                    BodyType = BodyType.Terrestrial, SupportsPopulations = true
                };
                MassVolumeDB planetMVDB       = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
                PositionDB   planetPositionDB = new PositionDB(system.Guid);
                planetLoP = i * 15;
                OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, planetMVDB.MassDry, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
                planetPositionDB.AbsolutePosition_AU = OrbitProcessor.GetPosition_AU(planetOrbitDB, StaticRefLib.CurrentDateTime);
                Entity planet = new Entity(system, new List <BaseDataBlob> {
                    planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB
                });
            }
            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(system.Guid);
            return(system);
        }
        public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (var componentDesign in componentInstances.SpecificInstances)
            {
                var componentVolume  = componentDesign.Key.GetDataBlob <MassVolumeDB>().Volume;
                var componentTonnage = componentDesign.Key.GetDataBlob <ComponentInfoDB>().SizeInTons;

                foreach (var componentInstance in componentDesign.Value)
                {
                    totalHTK     += componentInstance.GetDataBlob <ComponentInstanceInfoDB>().HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                    if (!componentInstances.ComponentDictionary.ContainsKey(componentInstance))
                    {
                        componentInstances.ComponentDictionary.Add(componentInstance, totalVolume);
                    }
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                ShipMovementProcessor.CalcMaxSpeed(shipEntity);
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.Volume = totalVolume;
        }
Пример #3
0
        internal static Entity NewInstanceFromDesignEntity(Entity design, Entity faction)
        {
            List <BaseDataBlob>     blobs = new List <BaseDataBlob>();
            ComponentInstanceInfoDB info  = new ComponentInstanceInfoDB(design);
            OwnedDB owned = new OwnedDB(faction);

            blobs.Add(info);
            blobs.Add(owned);
            blobs.Add(new DesignInfoDB(design));
            // Added because each component instance needs its own copy of this datablob

            //Components have a mass and volume.
            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

            if (design.HasDataBlob <BeamFireControlAtbDB>())
            {
                blobs.Add(new FireControlInstanceAbilityDB());
            }

            if (design.HasDataBlob <BeamWeaponAtbDB>() || design.HasDataBlob <SimpleBeamWeaponAtbDB>())
            {
                blobs.Add(new WeaponStateDB());
            }


            Entity newInstance = new Entity(design.Manager, blobs);

            return(newInstance);
        }
Пример #4
0
        /// <summary>
        /// Creates a star entity in the system.
        /// Does not initialize an orbit.
        /// </summary>
        public Entity CreateStar(StarSystem system, double mass, double radius, double age, string starClass, double temperature, float luminosity, SpectralType spectralType, string starName = null)
        {
            double          tempRange       = temperature / _galaxyGen.Settings.StarTemperatureBySpectralType[spectralType].Max; // temp range from 0 to 1.
            ushort          subDivision     = (ushort)Math.Round((1 - tempRange) * 10);
            LuminosityClass luminosityClass = LuminosityClass.V;

            if (starName == null)
            {
                starName = system.NameDB.DefaultName;
            }

            int starIndex = system.GetAllEntitiesWithDataBlob <StarInfoDB>().Count;

            starName += " " + (char)('A' + starIndex) + " " + spectralType + subDivision + luminosityClass;

            MassVolumeDB starMassVolumeDB = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            StarInfoDB   starInfoDB       = new StarInfoDB {
                Age = age, Class = starClass, Luminosity = luminosity, SpectralType = spectralType, Temperature = temperature, LuminosityClass = luminosityClass, SpectralSubDivision = subDivision
            };
            PositionDB starPositionDB = new PositionDB(new Vector3(0, 0, 0), system.Guid);
            NameDB     starNameDB     = new NameDB(starName);
            OrbitDB    starOrbitDB    = new OrbitDB();

            SensorProfileDB emmisionSignature = SensorProcessorTools.SetStarEmmisionSig(starInfoDB, starMassVolumeDB);

            return(new Entity(system, new List <BaseDataBlob> {
                starOrbitDB, starMassVolumeDB, starInfoDB, starNameDB, starPositionDB, emmisionSignature
            }));
        }
Пример #5
0
 public MassVolumeDB(MassVolumeDB massVolumeDB)
 {
     Mass       = massVolumeDB.Mass;
     Density    = massVolumeDB.Density;
     RadiusInAU = massVolumeDB.RadiusInAU;
     Volume_km3 = massVolumeDB.Volume_km3;
 }
Пример #6
0
 public MassVolumeDB(MassVolumeDB massVolumeDB)
 {
     Mass    = massVolumeDB.Mass;
     Density = massVolumeDB.Density;
     Radius  = massVolumeDB.Radius;
     Volume  = massVolumeDB.Volume;
 }
Пример #7
0
        /// <summary>
        /// Refreshes the properties of this ViewModel.
        ///
        /// If partialRefresh is set to true, the ViewModel will try to update only data changes during a pulse.
        /// </summary>
        public void Refresh(bool partialRefresh = false)
        {
            // Get up-to-date datablobs for this entity.
            PositionDB positionDB = _entity.GetDataBlob <PositionDB>();

            UpdateProperties(positionDB);

            SystemBodyInfoDB systemBodyDB = _entity.GetDataBlob <SystemBodyInfoDB>();

            UpdateProperties(systemBodyDB, partialRefresh);

            NameDB nameDB = _entity.GetDataBlob <NameDB>();

            UpdateProperties(nameDB);

            //AtmosphereDB atmosphereDB = _entity.GetDataBlob<AtmosphereDB>();
            //UpdateProperties(atmosphereDB);

            // Check if we're doing a full refresh.
            if (!partialRefresh)
            {
                OrbitDB orbitDB = _entity.GetDataBlob <OrbitDB>();
                UpdateProperties(orbitDB);

                MassVolumeDB massVolumeDB = _entity.GetDataBlob <MassVolumeDB>();
                UpdateProperties(massVolumeDB);
            }
        }
Пример #8
0
 public MassVolumeDB(MassVolumeDB massVolumeDB)
 {
     MassDry     = massVolumeDB.MassDry;
     Density_gcm = massVolumeDB.Density_gcm;
     RadiusInAU  = massVolumeDB.RadiusInAU;
     Volume_km3  = massVolumeDB.Volume_km3;
 }
Пример #9
0
        /// <summary>
        /// Generates Data for a star based on it's spectral type and populates it with the data.
        /// </summary>
        /// <remarks>
        /// This function randomly generates the Radius, Temperature, Luminosity, Mass and Age of a star and then returns a star populated with those generated values.
        /// What follows is a brief description of how that is done for each data point:
        /// <list type="Bullet">
        /// <item>
        /// <b>Temperature:</b> The Temp. of the star is obtained by using the Randon.Next(min, max) function to get a random Temp. in the range a star of the given
        /// spectral type.
        /// </item>
        /// <item>
        /// <b>Luminosity:</b> The Luminosity of a star is calculated by using the RNG_NextDoubleRange() function to get a random Luminosity in the range a star of the
        /// given spectral type.
        /// </item>
        /// <item>
        /// <b>Age:</b> The possible ages for a star depend largely on its mass. The bigger and heaver the star the more pressure is put on its core where fusion occur
        /// which increases the rate that it burns Hydrogen which reduces the life of the star. The Big O class stars only last a few million years before either
        /// going Hyper Nova or devolving into a class B star. on the other hand a class G star (like Sol) has a life expectancy of about 10 billion years while a
        /// little class M star could last 100 billion years or more (hard to tell given that the Milky way is 13.2 billion years old and the universe is only
        /// about a billion years older then that). Given this we first use the mass of the star to produce a number between 0 and 1 that we can use to pick a
        /// possible age from the range (just like all the above). To get the number between 0 and 1 we use the following formula:
        /// <c>1 - Mass / MaxMassOfStarOfThisType</c>
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="starMVDB">The SystemBodyDB of the star.</param>
        /// <param name="spectralType">The Spectral Type of the star.</param>
        /// <param name="randomSelection">Random selection to generate consistent values.</param>
        /// <returns>A StarInfoDB Populated with data generated based on Spectral Type and SystemBodyDB information provided.</returns>
        private StarInfoDB GenerateStarInfo(MassVolumeDB starMVDB, SpectralType spectralType, double randomSelection)
        {
            double maxStarAge = _galaxyGen.Settings.StarAgeBySpectralType[spectralType].Max;

            StarInfoDB starData = new StarInfoDB {// for star age we will make it proportional to the inverse of the stars mass ratio (for that type of star).
                // while this will produce the same age for the same mass/type of star the chances of getting the same
                // mass/type are tiny. Tho there will still be the obvious inverse relationship here.
                Age          = (1 - starMVDB.Mass / _galaxyGen.Settings.StarMassBySpectralType[spectralType].Max) * maxStarAge,
                SpectralType = spectralType,
                Temperature  = (uint)Math.Round(GMath.SelectFromRange(_galaxyGen.Settings.StarTemperatureBySpectralType[spectralType], randomSelection)),
                Luminosity   = (float)GMath.SelectFromRange(_galaxyGen.Settings.StarLuminosityBySpectralType[spectralType], randomSelection)
            };

            // Generate a string specifying the full spectral class form a star.
            // start by getting the sub-division, which is based on temp.
            double sub = starData.Temperature / _galaxyGen.Settings.StarTemperatureBySpectralType[starData.SpectralType].Max; // temp range from 0 to 1.

            starData.SpectralSubDivision = (ushort)Math.Round((1 - sub) * 10);                                                // invert temp range as 0 is hottest, 9 is coolest.

            // now get the luminosity class
            //< @todo For right now everthing is just main sequence. see http://en.wikipedia.org/wiki/Stellar_classification
            // on how this should be done. For right now tho class V is fine (its just flavor text).
            starData.LuminosityClass = LuminosityClass.V;

            // finally add them all up to get the class string:
            starData.Class = starData.SpectralType + starData.SpectralSubDivision.ToString() + "-" + starData.LuminosityClass;

            return(starData);
        }
Пример #10
0
        internal static Entity NewInstanceFromDesignEntity(Entity design, Entity faction, FactionOwnerDB ownerdb, EntityManager manager)
        {
            List <BaseDataBlob>     blobs = new List <BaseDataBlob>();
            ComponentInstanceInfoDB info  = new ComponentInstanceInfoDB(design);

            blobs.Add(info);
            blobs.Add(new DesignInfoDB(design));
            // Added because each component instance needs its own copy of this datablob

            //Components have a mass and volume.
            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);
            //TODO: this seems ugly, consider using an Interface on the datablobs for this?
            if (design.HasDataBlob <BeamFireControlAtbDB>())
            {
                blobs.Add(new FireControlInstanceAbilityDB());
            }

            if (design.HasDataBlob <BeamWeaponAtbDB>() || design.HasDataBlob <SimpleBeamWeaponAtbDB>())
            {
                blobs.Add(new WeaponStateDB());
            }
            if (design.HasDataBlob <SensorReceverAtbDB>())
            {
                blobs.Add((SensorReceverAtbDB)design.GetDataBlob <SensorReceverAtbDB>().Clone());
            }

            Entity newInstance = new Entity(manager, blobs);

            new OwnedDB(faction, newInstance); //the constructor of OwnedDB sets itself to the entity
            return(newInstance);
        }
Пример #11
0
        /// <summary>
        /// Generates a n ew MassVolumeDB from mass and density, calculating radius and volume.
        /// </summary>
        /// <param name="mass">Mass in Kg</param>
        /// <param name="density">Density in Kg/cm^3</param>
        /// <returns></returns>
        internal static MassVolumeDB NewFromMassAndDensity(double mass, double density)
        {
            var mvDB = new MassVolumeDB {
                Mass = mass, Density = density, Volume = CalculateVolume(mass, density), Radius = CalculateRadius(mass, density)
            };

            return(mvDB);
        }
Пример #12
0
        /// <summary>
        /// Generates a n ew MassVolumeDB from mass and density, calculating radius_au and volume.
        /// </summary>
        /// <param name="mass">Mass in Kg</param>
        /// <param name="density">Density in Kg/cm^3</param>
        /// <returns></returns>
        internal static MassVolumeDB NewFromMassAndDensity(double mass, double density)
        {
            var mvDB = new MassVolumeDB {
                Mass = mass, Density = density, Volume_km3 = CalculateVolume_Km3_FromMassAndDesity(mass, density), RadiusInAU = CalculateRadius_Au(mass, density)
            };

            return(mvDB);
        }
Пример #13
0
 void Update(MassVolumeDB origionalDB, SensorInfoDB sensorInfo)
 {
     //TODO: add rand from sensorInfo.
     Mass       = origionalDB.Mass;
     Density    = origionalDB.Density;
     RadiusInAU = origionalDB.RadiusInAU;
     Volume_km3 = origionalDB.Volume_km3;
 }
Пример #14
0
        /// <summary>
        /// creates an asteroid that will collide with the given entity on the given date.
        /// </summary>
        /// <param name="starSys"></param>
        /// <param name="target"></param>
        /// <param name="collisionDate"></param>
        /// <returns></returns>
        public static Entity CreateAsteroid(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
        {
            //todo rand these a bit.
            double radius = Distance.KmToAU(0.5);

            double mass;

            if (asteroidMass == -1.0)
            {
                mass = 1.5e+12; //about 1.5 billion tonne
            }
            else
            {
                mass = asteroidMass;
            }
            Vector3 velocity = new Vector3(8, 7, 0);

            var position     = new PositionDB(0, 0, 0, Guid.Empty);
            var massVolume   = MassVolumeDB.NewFromMassAndRadius(mass, radius);
            var planetInfo   = new SystemBodyInfoDB();
            var balisticTraj = new NewtonBalisticDB(target.Guid, collisionDate);
            var name         = new NameDB("Ellie");
            var AsteroidDmg  = new AsteroidDamageDB();
            var sensorPfil   = new SensorProfileDB();

            planetInfo.SupportsPopulations = false;
            planetInfo.BodyType            = BodyType.Asteroid;

            Vector3  targetPos       = OrbitProcessor.GetAbsolutePosition_AU(target.GetDataBlob <OrbitDB>(), collisionDate);
            TimeSpan timeToCollision = collisionDate - StaticRefLib.CurrentDateTime;


            Vector3 offset = velocity * timeToCollision.TotalSeconds;

            targetPos -= Distance.KmToAU(offset);
            position.AbsolutePosition_AU = targetPos;
            position.SystemGuid          = starSys.Guid;
            balisticTraj.CurrentSpeed    = velocity;



            var planetDBs = new List <BaseDataBlob>
            {
                position,
                massVolume,
                planetInfo,
                name,
                balisticTraj,
                AsteroidDmg,
                sensorPfil
            };

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }
Пример #15
0
        /// <summary>
        /// Generates a new MassVolumeDB from mass and radius, calculating density and volume.
        /// </summary>
        /// <param name="mass">Mass in Kg.</param>
        /// <param name="radius">Radius in AU</param>
        /// <returns></returns>
        internal static MassVolumeDB NewFromMassAndRadius(double mass, double radius)
        {
            var mvDB = new MassVolumeDB {
                Mass = mass, Radius = radius, Volume = CalculateVolume(radius)
            };

            mvDB.Density = CalculateDensity(mass, mvDB.Volume);

            return(mvDB);
        }
Пример #16
0
        /// <summary>
        /// Generates a new MassVolumeDB from mass and volume, calculating deinsity and radius_au.
        /// </summary>
        /// <param name="mass">Mass in Kg</param>
        /// <param name="volume">Density in m^3</param>
        /// <returns></returns>
        internal static MassVolumeDB NewFromMassAndVolume(double mass, double volume_m3)
        {
            var density = CalculateDensity(mass, volume_m3);
            var rad     = CalculateRadius_m(mass, density);
            var mvDB    = new MassVolumeDB {
                Mass = mass, Volume_m3 = volume_m3, Density = density, RadiusInM = rad
            };

            return(mvDB);
        }
Пример #17
0
        internal static MassVolumeDB NewFromMassAndRadius_m(double mass, double radius_m)
        {
            var mvDB = new MassVolumeDB {
                Mass = mass, RadiusInM = radius_m, Volume_m3 = CalculateVolume_m3(radius_m)
            };

            mvDB.Density = CalculateDensity(mass, mvDB.Volume_m3);

            return(mvDB);
        }
Пример #18
0
        /// <summary>
        /// Generates a new MassVolumeDB from mass and radius_au, calculating density and volume.
        /// </summary>
        /// <param name="mass">Mass in Kg.</param>
        /// <param name="radius_au">Radius in AU</param>
        /// <returns></returns>
        internal static MassVolumeDB NewFromMassAndRadius_AU(double mass, double radius_au)
        {
            var mvDB = new MassVolumeDB {
                MassDry = mass, RadiusInAU = radius_au, Volume_km3 = CalculateVolume_Km3(radius_au)
            };

            mvDB.Density_gcm = CalculateDensity(mass, mvDB.Volume_m3);

            return(mvDB);
        }
Пример #19
0
        /// <summary>
        /// This asteroid was destroyed, see if it is big enough for child asteroids to spawn, and if so spawn them.
        /// </summary>
        /// <param name="Asteroid"></param>
        internal static void SpawnSubAsteroids(Entity Asteroid)
        {
            Game         game = Asteroid.Manager.Game;
            MassVolumeDB ADB  = Asteroid.GetDataBlob <MassVolumeDB>();

            //const double massDefault = 1.5e+12; //150 B tonnes?
            const double massThreshold = 1.5e+9; //150 M tonnes?

            if (ADB.Mass > massThreshold)
            {
                //spawn new asteroids. call the asteroid factory?

                double newMass = ADB.Mass * 0.4; //add a random factor into this? do we care? will mass be printed to the player?

                NewtonBalisticDB nDB = Asteroid.GetDataBlob <NewtonBalisticDB>();
                PositionDB       pDB = Asteroid.GetDataBlob <PositionDB>();

                StarSystem mySystem;
                if (!game.Systems.TryGetValue(pDB.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(pDB.SystemGuid);
                }

                Entity myTarget;
                if (!mySystem.FindEntityByGuid(nDB.TargetGuid, out myTarget))
                {
                    throw new GuidNotFoundException(nDB.TargetGuid);
                }

                //public static Entity CreateAsteroid(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
                //I need the target entity, the collisionDate, and the starSystem. I may have starsystem from guid.
                //Ok so this should create the asteroid without having to add the new asteroids to a list. as that is done in the factory.
                Entity newAsteroid1 = AsteroidFactory.CreateAsteroid(mySystem, myTarget, nDB.CollisionDate, newMass);
                Entity newAsteroid2 = AsteroidFactory.CreateAsteroid(mySystem, myTarget, nDB.CollisionDate, newMass);

                mySystem.RemoveEntity(Asteroid);

                //Randomize the number of created asteroids?
            }
            else
            {
                //delete the existing asteroid.
                PositionDB pDB = Asteroid.GetDataBlob <PositionDB>();

                StarSystem mySystem;
                if (!game.Systems.TryGetValue(pDB.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(pDB.SystemGuid);
                }

                mySystem.RemoveEntity(Asteroid);
            }
        }
Пример #20
0
        private void UpdateProperties([NotNull] MassVolumeDB massVolumeDB)
        {
            if (massVolumeDB == null)
            {
                throw new ArgumentNullException("massVolumeDB");
            }

            Mass           = massVolumeDB.Mass;
            Density        = massVolumeDB.Density;
            Radius         = massVolumeDB.RadiusInAU;
            Volume         = massVolumeDB.Volume;
            SurfaceGravity = massVolumeDB.SurfaceGravity;
        }
Пример #21
0
        /// <summary>
        /// Creates a new colony with zero population.
        /// </summary>
        /// <param name="systemEntityManager"></param>
        /// <param name="factionEntity"></param>
        /// <returns></returns>
        public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity)
        {
            List <BaseDataBlob> blobs = new List <BaseDataBlob>();
            string planetName         = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity.Guid);
            NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.

            name.SetName(factionEntity.Guid, name.DefaultName);

            blobs.Add(name);
            ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity);

            blobs.Add(colonyInfoDB);
            ColonyBonusesDB colonyBonuses = new ColonyBonusesDB();

            blobs.Add(colonyBonuses);
            MiningDB colonyMinesDB = new MiningDB();

            blobs.Add(colonyMinesDB);
            RefiningDB colonyRefining = new RefiningDB();

            blobs.Add(colonyRefining);
            ConstructionDB colonyConstruction = new ConstructionDB();

            blobs.Add(colonyConstruction);
            OrderableDB orderableDB = new OrderableDB();

            blobs.Add(orderableDB);
            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

            TeamsHousedDB th = new TeamsHousedDB();

            blobs.Add(th);

            //installations get added to the componentInstancesDB
            ComponentInstancesDB installations = new ComponentInstancesDB();

            blobs.Add(installations);

            Entity colonyEntity = new Entity(planetEntity.Manager, factionEntity.Guid, blobs);
            var    factionInfo  = factionEntity.GetDataBlob <FactionInfoDB>();

            factionInfo.Colonies.Add(colonyEntity);
            factionEntity.GetDataBlob <FactionOwnerDB>().SetOwned(colonyEntity);
            planetEntity.GetDataBlob <SystemBodyInfoDB>().Colonies.Add(colonyEntity);
            return(colonyEntity);
        }
Пример #22
0
        /// <summary>
        /// This asteroid was destroyed, see if it is big enough for child asteroids to spawn, and if so spawn them.
        /// </summary>
        /// <param name="Asteroid"></param>
        internal static void SpawnSubAsteroids(Entity Asteroid, DateTime atDateTime)
        {
            Game         game = Asteroid.Manager.Game;
            MassVolumeDB ADB  = Asteroid.GetDataBlob <MassVolumeDB>();

            //const double massDefault = 1.5e+12; //150 B tonnes?
            const double massThreshold = 1.5e+9; //150 M tonnes?

            if (ADB.Mass > massThreshold)
            {
                //spawn new asteroids. call the asteroid factory?

                double newMass = ADB.Mass * 0.4; //add a random factor into this? do we care? will mass be printed to the player?

                OrbitDB    origOrbit = Asteroid.GetDataBlob <OrbitDB>();
                PositionDB pDB       = Asteroid.GetDataBlob <PositionDB>();

                EntityManager mySystem = Asteroid.Manager;


                var origVel = OrbitProcessor.AbsoluteOrbitalVector_AU(origOrbit, atDateTime);

                //public static Entity CreateAsteroid(StarSystem starSys, Entity target, DateTime collisionDate, double asteroidMass = -1.0)
                //I need the target entity, the collisionDate, and the starSystem. I may have starsystem from guid.
                //Ok so this should create the asteroid without having to add the new asteroids to a list. as that is done in the factory.
                Entity newAsteroid1 = AsteroidFactory.CreateAsteroid4(pDB.AbsolutePosition_AU, origOrbit, atDateTime, newMass);
                //var newOrbit = OrbitDB.FromVector(origOrbit.Parent, )
                Entity newAsteroid2 = AsteroidFactory.CreateAsteroid4(pDB.AbsolutePosition_AU, origOrbit, atDateTime, newMass);

                mySystem.RemoveEntity(Asteroid);

                //Randomize the number of created asteroids?
            }
            else
            {
                //delete the existing asteroid.
                PositionDB pDB = Asteroid.GetDataBlob <PositionDB>();

                StarSystem mySystem;
                if (!game.Systems.TryGetValue(pDB.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(pDB.SystemGuid);
                }

                mySystem.RemoveEntity(Asteroid);
            }
        }
Пример #23
0
 private void OnTargetSelectonChange(int oldSelection, int newSelection)
 {
     if (_selectedEntity.HasDataBlob <MassVolumeDB>())
     {
         MassVolumeDB massdb = _selectedEntity.GetDataBlob <MassVolumeDB>();
         if (massdb.Mass >= 1.5E15)
         {
             CanOrbitSelected = true;
         }
         else
         {
             CanOrbitSelected = false;
         }
         OnPropertyChanged(nameof(CanOrbitSelected));
     }
     CanMatchSelected = _selectedEntity.HasDataBlob <OrbitDB>();
     OnPropertyChanged(nameof(CanMatchSelected));
 }
Пример #24
0
        /// <summary>
        /// Probibly only needs to be done at star creation, unless we do funky stuff like change a stars temprature and stuff.
        /// </summary>
        /// <returns>The star emmision sig.</returns>
        /// <param name="starInfoDB">Star info db.</param>
        /// <param name="starMassVolumeDB">Star mass volume db.</param>
        internal static SensorProfileDB SetStarEmmisionSig(StarInfoDB starInfoDB, MassVolumeDB starMassVolumeDB)
        {
            var    tempDegreesC  = starInfoDB.Temperature;
            var    kelvin        = tempDegreesC + 273.15;
            double b             = 2898000;                          //Wien's displacement constant for nanometers.
            var    wavelength    = b / kelvin;                       //Wien's displacement law https://en.wikipedia.org/wiki/Wien%27s_displacement_law
            var    magnitudeInKW = starInfoDB.Luminosity * 3.827e23; //tempDegreesC / starMassVolumeDB.Volume_km3; //maybe this should be lum / volume?

            //-300, + 600, semi arbitrary number pulled outa my ass from 10min of internet research.
            EMWaveForm waveform = new EMWaveForm(wavelength - 300, wavelength, wavelength + 600);


            var emisionSignature = new SensorProfileDB()
            {
            };

            emisionSignature.EmittedEMSpectra.Add(waveform, magnitudeInKW);// this will need adjusting...

            return(emisionSignature);
        }
Пример #25
0
        /// <summary>
        /// Probibly only needs to be done at star creation, unless we do funky stuff like change a stars temprature and stuff.
        /// </summary>
        /// <returns>The star emmision sig.</returns>
        /// <param name="starInfoDB">Star info db.</param>
        /// <param name="starMassVolumeDB">Star mass volume db.</param>
        internal static SensorProfileDB SetStarEmmisionSig(StarInfoDB starInfoDB, MassVolumeDB starMassVolumeDB)
        {
            var        tempDegreesC  = starInfoDB.Temperature;
            var        kelvin        = tempDegreesC + 273.15;
            var        wavelength    = 2.9 * Math.Pow(10, 6) / kelvin;
            var        magnitudeInKW = starInfoDB.Luminosity * 3.827e23; //tempDegreesC / starMassVolumeDB.Volume; //maybe this should be lum / volume?
            EMWaveForm waveform      = new EMWaveForm()
            {
                WavelengthAverage_nm = wavelength,
                WavelengthMin_nm     = wavelength - 300, //3k angstrom, semi arbitrary number pulled outa my ass from 10min of internet research.
                WavelengthMax_nm     = wavelength + 600
            };

            var emisionSignature = new SensorProfileDB()
            {
            };

            emisionSignature.EmittedEMSpectra.Add(waveform, magnitudeInKW);// this will need adjusting...

            return(emisionSignature);
        }
Пример #26
0
        /// <summary>
        /// Creates a new colony with zero population.
        /// </summary>
        /// <param name="systemEntityManager"></param>
        /// <param name="factionEntity"></param>
        /// <returns></returns>
        public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity)
        {
            List <BaseDataBlob> blobs = new List <BaseDataBlob>();
            string planetName         = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity);
            var    OwnedDB            = new OwnedDB(factionEntity);

            blobs.Add(OwnedDB);
            NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.

            blobs.Add(name);
            ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity);

            blobs.Add(colonyInfoDB);
            ColonyBonusesDB colonyBonuses = new ColonyBonusesDB();

            blobs.Add(colonyBonuses);
            ColonyMinesDB colonyMinesDB = new ColonyMinesDB();

            blobs.Add(colonyMinesDB);
            ColonyRefiningDB colonyRefining = new ColonyRefiningDB();

            blobs.Add(colonyRefining);
            ColonyConstructionDB colonyConstruction = new ColonyConstructionDB();

            blobs.Add(colonyConstruction);

            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

            //installations get added to the componentInstancesDB
            ComponentInstancesDB installations = new ComponentInstancesDB();

            blobs.Add(installations);

            Entity colonyEntity = new Entity(planetEntity.Manager, blobs);

            factionEntity.GetDataBlob <FactionInfoDB>().Colonies.Add(colonyEntity);
            return(colonyEntity);
        }
Пример #27
0
        internal static Entity NewInstanceFromDesignEntity(Entity design, Guid factionID, EntityManager manager)
        {
            List <BaseDataBlob>     blobs = new List <BaseDataBlob>();
            ComponentInstanceInfoDB info  = new ComponentInstanceInfoDB(design);
            NameDB name = new NameDB(design.GetDataBlob <NameDB>().DefaultName);

            name.SetName(factionID, design.GetDataBlob <NameDB>().GetName(factionID));

            blobs.Add(info);
            blobs.Add(name);
            blobs.Add(new DesignInfoDB(design));
            // Added because each component instance needs its own copy of this datablob

            //Components have a mass and volume.
            MassVolumeDB mvDB = (MassVolumeDB)design.GetDataBlob <MassVolumeDB>().Clone();

            blobs.Add(mvDB);

            Entity newInstance = new Entity(manager, factionID, blobs);

            return(newInstance);
        }
Пример #28
0
        private static SpeciesDB CreateSpeciesDB_FromPlanet(Entity planetEntity, int?seed = null)
        {
            Random rnd;

            if (seed != null)
            {
                rnd = new Random((int)seed);
            }
            else
            {
                rnd = new Random();
            }

            MassVolumeDB     masvolinfo  = planetEntity.GetDataBlob <MassVolumeDB>();
            SystemBodyInfoDB sysbodyinfo = planetEntity.GetDataBlob <SystemBodyInfoDB>();
            AtmosphereDB     atmoinfo    = planetEntity.GetDataBlob <AtmosphereDB>();


            //throw new NotImplementedException();
            double    baseGravity = masvolinfo.SurfaceGravity;
            double    minimumGravityConstraint     = 0.1;//rnd.Next(planetInfo.SurfaceGravity, 0.1);
            double    maximumGravityConstraint     = 1.9;
            double    basePressure                 = atmoinfo.Pressure;
            double    minimumPressureConstraint    = 0.4;
            double    maximumPressureConstraint    = 4.0;
            double    baseTemperature              = sysbodyinfo.BaseTemperature;
            double    minimumTemperatureConstraint = -15.0;
            double    maximumTemperatureConstraint = 45.0;
            SpeciesDB species = new SpeciesDB(baseGravity,
                                              minimumGravityConstraint, maximumGravityConstraint,
                                              basePressure, minimumPressureConstraint,
                                              maximumPressureConstraint, baseTemperature,
                                              minimumTemperatureConstraint, maximumTemperatureConstraint);

            return(species);
        }
        public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (KeyValuePair <Guid, List <ComponentInstance> > instance in componentInstances.GetComponentsByDesigns())
            {
                var componentVolume  = componentInstances.AllDesigns[instance.Key].VolumePerUnit;
                var componentTonnage = componentInstances.AllDesigns[instance.Key].MassPerUnit;

                foreach (var componentInstance in instance.Value)
                {
                    totalHTK     += componentInstance.HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                if (shipEntity.HasDataBlob <WarpAbilityDB>())
                {
                    ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(shipEntity);
                }
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.MassDry     = totalTonnage;
            mvDB.Volume_m3   = totalVolume;
            mvDB.Density_gcm = MassVolumeDB.CalculateDensity(totalTonnage, totalVolume);
            mvDB.RadiusInAU  = MassVolumeDB.CalculateRadius_Au(totalTonnage, mvDB.Density_gcm);
        }
Пример #30
0
        /// <summary>
        /// probibly only needs to be done at entity creation, once the bodies mass is set.
        /// </summary>
        /// <returns>The emmision sig.</returns>
        /// <param name="sysBodyInfoDB">Sys body info db.</param>
        /// <param name="massVolDB">Mass vol db.</param>
        internal static void PlanetEmmisionSig(SensorProfileDB profile, SystemBodyInfoDB sysBodyInfoDB, MassVolumeDB massVolDB)
        {
            var        tempDegreesC = sysBodyInfoDB.BaseTemperature;
            var        kelvin       = tempDegreesC + 273.15;
            var        wavelength   = 2.9 * Math.Pow(10, 6) / kelvin;
            var        magnitude    = tempDegreesC / massVolDB.Volume;
            EMWaveForm waveform     = new EMWaveForm()
            {
                WavelengthAverage_nm = wavelength,
                WavelengthMin_nm     = wavelength - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research.
                WavelengthMax_nm     = wavelength + 600
            };

            profile.EmittedEMSpectra.Add(waveform, magnitude);//TODO this may need adjusting to make good balanced detections.
            profile.Reflectivity = sysBodyInfoDB.Albedo;
        }