Example #1
0
        /// <summary>
        /// Creates an test system with planets of varying eccentricity.
        /// Adds to game.StarSystems
        /// </summary>
        public StarSystem CreateEccTest(Game game)
        {
            StarSystem system = new StarSystem(game, "Eccentricity test", -1);

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

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


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


            for (int i = 0; i < 16; i++)
            {
                NameDB planetNameDB = new NameDB("planet" + i);

                SystemBodyInfoDB planetBodyDB = new SystemBodyInfoDB {
                    BodyType = BodyType.Terrestrial, SupportsPopulations = true
                };
                MassVolumeDB planetMVDB       = MassVolumeDB.NewFromMassAndRadius(3.3022E23, Distance.KmToAU(2439.7));
                PositionDB   planetPositionDB = new PositionDB(system.Guid);
                planetEccentricity = i / 16.0;
                OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
                planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime);
                Entity planet = new Entity(system.SystemManager, new List <BaseDataBlob> {
                    planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB
                });
            }
            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(system.Guid);
            return(system);
        }
Example #2
0
        /// <summary>
        /// Creates our own solar system.
        /// This probibly needs to be Json! (since we're getting atmo stuff)
        /// Adds sol to game.StarSystems.
        /// </summary>
        public StarSystem CreateSol(Game game)
        {
            // WIP Function. Not complete.
            StarSystem sol = new StarSystem(game, "Sol", -1);

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

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

            SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f
            };                                                                                                                                      //Albedo = 0.068f
            MassVolumeDB mercuryMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
            NameDB       mercuryNameDB       = new NameDB("Mercury");
            double       mercurySemiMajAxis  = 0.387098;
            double       mercuryEccentricity = 0.205630;
            double       mercuryInclination  = 0;
            double       mercuryLoAN         = 48.33167;
            double       mercuryLoP          = 77.45645;
            double       mercuryMeanLongd    = 252.25084;
            OrbitDB      mercuryOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000);

            mercuryBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, mercuryOrbitDB);
            PositionDB mercuryPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            //AtmosphereDB mercuryAtmo = new AtmosphereDB();
            SensorProfileDB sensorProfile = new SensorProfileDB();
            Entity          mercury       = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB);

            SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f
            };
            MassVolumeDB venusMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8));
            NameDB       venusNameDB       = new NameDB("Venus");
            double       venusSemiMajAxis  = 0.72333199;
            double       venusEccentricity = 0.00677323;
            double       venusInclination  = 0;
            double       venusLoAN         = 76.68069;
            double       venusLoP          = 131.53298;
            double       venusMeanLongd    = 181.97973;

            OrbitDB venusOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000);

            venusBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, venusOrbitDB);
            PositionDB venusPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity venus = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB);

            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f
            };
            MassVolumeDB earthMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1));
            NameDB       earthNameDB       = new NameDB("Earth");
            double       earthSemiMajAxis  = 1.00000011;
            double       earthEccentricity = 0.01671022;
            double       earthInclination  = 0;
            double       earthLoAN         = -11.26064;
            double       earthLoP          = 102.94719;
            double       earthMeanLongd    = 100.46435;
            OrbitDB      earthOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000);

            earthBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB);
            earthBodyDB.Tectonics       = TectonicActivity.EarthLike;
            PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f);
            AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?

            sensorProfile = new SensorProfileDB();
            Entity earth = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB
            });

            _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB);


            SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Moon, SupportsPopulations = true
            };
            MassVolumeDB lunaMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14));
            NameDB       lunaNameDB       = new NameDB("Luna");
            double       lunaSemiMajAxis  = Distance.KmToAU(0.3844E6);
            double       lunaEccentricity = 0.0549;
            double       lunaInclination  = 0;//5.1;
            // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively.
            // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression.
            double  lunaLoAN        = 125.08;
            double  lunaAoP         = 318.0634;
            double  lunaMeanAnomaly = 115.3654;
            OrbitDB lunaOrbitDB     = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000);

            lunaBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, earthOrbitDB); //yes, using earth orbit here, since this is the DB it calculates the average distance from.

            PositionDB lunaPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth);

            sensorProfile = new SensorProfileDB();
            Entity luna = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB);


            SystemBodyInfoDB marsBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.25f
            };
            MassVolumeDB marsMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.64174E24, Distance.KmToAU(3396.2));
            NameDB       marsNameDB       = new NameDB("Mars");
            double       marsSemiMajAxis  = Distance.KmToAU(227.92E6);
            double       marsEccentricity = 0.0934; //wiki says .0934
            double       marsInclination  = 0;      //1.85;
            double       marsLoAN         = 49.57854;
            double       marsAoP          = 336.04084;
            double       marsMeanLong     = 355.45332;
            OrbitDB      marsOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, marsMVDB.MassDry, marsSemiMajAxis, marsEccentricity, marsInclination, marsLoAN, marsAoP, marsMeanLong, GalaxyGen.Settings.J2000);

            marsBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, marsOrbitDB);
            Dictionary <AtmosphericGasSD, float> marsAtmoGasses = new Dictionary <AtmosphericGasSD, float>();

            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(12), 0.95f * 0.01f);   // C02% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.027f * 0.01f);   // N% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.007f * 0.01f);   // O% * Mars Atms
            marsAtmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.016f * 0.01f);  // Ar% * Mars Atms
            AtmosphereDB marsAtmo       = new AtmosphereDB(0.087f, false, 0, 0, 0, -55, marsAtmoGasses);
            PositionDB   marsPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(marsOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity mars = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, marsPositionDB, marsBodyDB, marsMVDB, marsNameDB, marsOrbitDB, marsAtmo
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mars);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, marsBodyDB, marsMVDB);


            SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f
            };                                                                                                                                 //Albedo = 0.04f
            MassVolumeDB halleysMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11));
            NameDB       halleysNameDB       = new NameDB("Halleys Comet");
            double       halleysSemiMajAxis  = 17.834; //AU
            double       halleysEccentricity = 0.96714;
            double       halleysInclination  = 180;    //162.26° note retrograde orbit.
            double       halleysLoAN         = 58.42;  //°
            double       halleysAoP          = 111.33; //°
            double       halleysMeanAnomaly  = 38.38;  //°
            OrbitDB      halleysOrbitDB      = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17));

            halleysBodyDB.BaseTemperature = (float)SystemBodyFactory.CalculateBaseTemperatureOfBody(sun, halleysOrbitDB);
            PositionDB halleysPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID);

            sensorProfile = new SensorProfileDB();
            Entity halleysComet = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB);

            /*
             *
             * SystemBody Jupiter = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Jupiter.Name = "Jupiter";
             * Jupiter.Orbit = Orbit.FromMajorPlanetFormat(1898.3E24, sun.Orbit.Mass, 5.20336301, 0.04839266, 1.30530, 100.55615, 14.75385, 34.40438, GalaxyGen.J2000);
             * Jupiter.Radius = Distance.ToAU(71492);
             * Jupiter.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Jupiter.Position.System = Sol;
             * Jupiter.Position.X = x;
             * Jupiter.Position.Y = y;
             * sun.Planets.Add(Jupiter);
             *
             * SystemBody Saturn = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Saturn.Name = "Saturn";
             * Saturn.Orbit = Orbit.FromMajorPlanetFormat(568.36E24, sun.Orbit.Mass, 9.53707032, 0.05415060, 2.48446, 113.71504, 92.43194, 49.94432, GalaxyGen.J2000);
             * Saturn.Radius = Distance.ToAU(60268);
             * Saturn.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Saturn.Position.System = Sol;
             * Saturn.Position.X = x;
             * Saturn.Position.Y = y;
             * sun.Planets.Add(Saturn);
             *
             * SystemBody Uranus = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Uranus.Name = "Uranus";
             * Uranus.Orbit = Orbit.FromMajorPlanetFormat(86.816E24, sun.Orbit.Mass, 19.19126393, 0.04716771, 0.76986, 74.22988, 170.96424, 313.23218, GalaxyGen.J2000);
             * Uranus.Radius = Distance.ToAU(25559);
             * Uranus.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Uranus.Position.System = Sol;
             * Uranus.Position.X = x;
             * Uranus.Position.Y = y;
             * sun.Planets.Add(Uranus);
             *
             * SystemBody Neptune = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Neptune.Name = "Neptune";
             * Neptune.Orbit = Orbit.FromMajorPlanetFormat(102E24, sun.Orbit.Mass, Distance.ToAU(4495.1E6), 0.011, 1.8, 131.72169, 44.97135, 304.88003, GalaxyGen.J2000);
             * Neptune.Radius = Distance.ToAU(24764);
             * Neptune.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Neptune.Position.System = Sol;
             * Neptune.Position.X = x;
             * Neptune.Position.Y = y;
             * sun.Planets.Add(Neptune);
             *
             * SystemBody Pluto = new SystemBody(sun, SystemBody.PlanetType.DwarfPlanet);
             * Pluto.Name = "Pluto";
             * Pluto.Orbit = Orbit.FromMajorPlanetFormat(0.0131E24, sun.Orbit.Mass, Distance.ToAU(5906.38E6), 0.24880766, 17.14175, 110.30347, 224.06676, 238.92881, GalaxyGen.J2000);
             * Pluto.Radius = Distance.ToAU(1195);
             * Pluto.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Pluto.Position.System = Sol;
             * Pluto.Position.X = x;
             * Pluto.Position.Y = y;
             * sun.Planets.Add(Pluto);
             *
             * GenerateJumpPoints(Sol);
             *
             * // Clean up cached RNG:
             * m_RNG = null;
             * GameState.Instance.StarSystems.Add(Sol);
             * GameState.Instance.StarSystemCurrentIndex++;
             */

            /*
             * double planetSemiMajAxis = 0.387098;
             * double planetEccentricity = 0.205630;
             * double planetInclination = 0;
             * double planetLoAN = 0;//48.33167;
             * double planetLoP = 0;//77.45645;
             * double planetMeanLongd = 252.25084;
             *
             * EMWaveForm waveform;
             *
             * for (int i = 0; i < 8; i++)
             * {
             *  NameDB planetNameDB = new NameDB("planetE" + 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(sol.ID);
             *  planetEccentricity = i * 2 / 16.0;
             *  OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
             *  planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime);
             *
             *  waveform = new EMWaveForm()
             *  {
             *      WavelengthAverage_nm = 600,
             *      WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research.
             *      WavelengthMax_nm = 600 + 600
             *  };
             *
             *  sensorProfile = new SensorProfileDB();
             *  sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23);
             *  Entity planet = new Entity(sol, new List<BaseDataBlob> { sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB });
             * }
             *
             * planetEccentricity = 0.9;
             * for (int i = 0; i < 8; i++)
             * {
             *  NameDB planetNameDB = new NameDB("planetL" + 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(sol.ID);
             *  planetLoP = i * 15;
             *  OrbitDB planetOrbitDB = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, planetMVDB.Mass, planetSemiMajAxis, planetEccentricity, planetInclination, planetLoAN, planetLoP, planetMeanLongd, GalaxyGen.Settings.J2000);
             *  planetPositionDB.AbsolutePosition = OrbitProcessor.GetPosition(planetOrbitDB, game.CurrentDateTime);
             *
             *  waveform = new EMWaveForm()
             *  {
             *      WavelengthAverage_nm = 600,
             *      WavelengthMin_nm = 600 - 400, //4k angstrom, semi arbitrary number pulled outa my ass from 0min of internet research.
             *      WavelengthMax_nm = 600 + 600
             *  };
             *
             *  sensorProfile = new SensorProfileDB();
             *  sensorProfile.EmittedEMSpectra.Add(waveform, 3.827e23);
             *  Entity planet = new Entity(sol, new List<BaseDataBlob> {sensorProfile, planetPositionDB, planetBodyDB, planetMVDB, planetNameDB, planetOrbitDB });
             * }
             */

            JPSurveyFactory.GenerateJPSurveyPoints(sol);

            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            return(sol);
        }
Example #3
0
        private static void SerializeBodyToXML(XmlDocument xmlDoc, XmlNode systemNode, Entity systemBody, OrbitDB orbit)
        {
            // get the datablobs:
            var systemBodyDB = systemBody.GetDataBlob <SystemBodyInfoDB>();
            var starIfnoDB   = systemBody.GetDataBlob <StarInfoDB>();
            var positionDB   = systemBody.GetDataBlob <PositionDB>();
            var massVolumeDB = systemBody.GetDataBlob <MassVolumeDB>();
            var nameDB       = systemBody.GetDataBlob <NameDB>();
            var atmosphereDB = systemBody.GetDataBlob <AtmosphereDB>();
            var ruinsDB      = systemBody.GetDataBlob <RuinsDB>();

            // create the body node:
            XmlNode bodyNode = xmlDoc.CreateNode(XmlNodeType.Element, "Body", "NS");

            // save parent id first:
            XmlNode varNode = xmlDoc.CreateNode(XmlNodeType.Element, "ParentID", "NS");

            if (orbit.Parent != null)
            {
                varNode.InnerText = orbit.Parent.Guid.ToString();
            }
            else
            {
                varNode.InnerText = Guid.Empty.ToString();
            }
            bodyNode.AppendChild(varNode);

            // then add our ID to at the end:
            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "ID", "NS");
            varNode.InnerText = systemBody.Guid.ToString();
            bodyNode.AppendChild(varNode);

            if (nameDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Name", "NS");
                varNode.InnerText = nameDB.DefaultName;
                bodyNode.AppendChild(varNode);
            }

            if (starIfnoDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Type", "NS");
                varNode.InnerText = starIfnoDB.SpectralType.ToString();
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Class", "NS");
                varNode.InnerText = starIfnoDB.Class;
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Age", "NS");
                varNode.InnerText = starIfnoDB.Age.ToString("N0");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "AverageEcoSphereRadius", "NS");
                varNode.InnerText = starIfnoDB.EcoSphereRadius.ToString("N3");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "MinEcoSphereRadius", "NS");
                varNode.InnerText = starIfnoDB.MinHabitableRadius.ToString("N4");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "MaxEcoSphereRadius", "NS");
                varNode.InnerText = starIfnoDB.MaxHabitableRadius.ToString("N4");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Luminosity", "NS");
                varNode.InnerText = starIfnoDB.Luminosity.ToString("N4");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Temperature", "NS");
                varNode.InnerText = starIfnoDB.Temperature.ToString("N0");
                bodyNode.AppendChild(varNode);
            }

            if (massVolumeDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "MassInKG", "NS");
                varNode.InnerText = massVolumeDB.Mass.ToString("N0");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "MassInEarthMasses", "NS");
                varNode.InnerText = (massVolumeDB.Mass / GameConstants.Units.EarthMassInKG).ToString("N2");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Density", "NS");
                varNode.InnerText = massVolumeDB.Density.ToString("N4");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Radius", "NS");
                varNode.InnerText = massVolumeDB.RadiusInKM.ToString("N0");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Volume", "NS");
                varNode.InnerText = massVolumeDB.Volume.ToString("N0");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "SurfaceGravity", "NS");
                varNode.InnerText = massVolumeDB.SurfaceGravity.ToString("N4");
                bodyNode.AppendChild(varNode);
            }

            // add orbit details:
            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "SemiMajorAxis", "NS");
            varNode.InnerText = orbit.SemiMajorAxis.ToString("N3");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Apoapsis", "NS");
            varNode.InnerText = orbit.Apoapsis.ToString("N3");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Periapsis", "NS");
            varNode.InnerText = orbit.Periapsis.ToString("N3");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Year", "NS");
            varNode.InnerText = orbit.OrbitalPeriod.ToString("dd\\:hh\\:mm");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Eccentricity", "NS");
            varNode.InnerText = orbit.Eccentricity.ToString("N3");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Inclination", "NS");
            varNode.InnerText = orbit.Inclination.ToString("N2");
            bodyNode.AppendChild(varNode);

            varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Children", "NS");
            varNode.InnerText = orbit.Children.Count.ToString();
            bodyNode.AppendChild(varNode);

            if (positionDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "PositionInAU", "NS");
                varNode.InnerText = "(" + positionDB.X.ToString("N3") + ", " + positionDB.Y.ToString("N3") + ", " + positionDB.Z.ToString("N3") + ")";
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "PositionInKm", "NS");
                varNode.InnerText = "(" + positionDB.XInKm.ToString("N3") + ", " + positionDB.YInKm.ToString("N3") + ", " + positionDB.ZInKm.ToString("N3") + ")";
                bodyNode.AppendChild(varNode);
            }

            if (systemBodyDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Type", "NS");
                varNode.InnerText = systemBodyDB.BodyType.ToString();
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "AxialTilt", "NS");
                varNode.InnerText = systemBodyDB.AxialTilt.ToString("N1");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Temperature", "NS");
                varNode.InnerText = systemBodyDB.BaseTemperature.ToString("N1");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "LengthOfDay", "NS");
                varNode.InnerText = systemBodyDB.LengthOfDay.ToString("g");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "MagneticField", "NS");
                varNode.InnerText = systemBodyDB.MagneticField.ToString("N2");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Tectonics", "NS");
                varNode.InnerText = systemBodyDB.Tectonics.ToString();
                bodyNode.AppendChild(varNode);
            }

            if (atmosphereDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Atmosphere", "NS");
                varNode.InnerText = atmosphereDB.AtomsphereDescriptionInPercent;
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "AtmosphereInATM", "NS");
                varNode.InnerText = atmosphereDB.AtomsphereDescriptionAtm;
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "Pressure", "NS");
                varNode.InnerText = atmosphereDB.Pressure.ToString("N2");
                bodyNode.AppendChild(varNode);

                //varNode = xmlDoc.CreateNode(XmlNodeType.Element, "Albedo", "NS");
                //varNode.InnerText = atmosphereDB.Albedo.ToString("p1");
                //bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "SurfaceTemperature", "NS");
                varNode.InnerText = atmosphereDB.SurfaceTemperature.ToString("N1");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "GreenhouseFactor", "NS");
                varNode.InnerText = atmosphereDB.GreenhouseFactor.ToString("N2");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "GreenhousePressure", "NS");
                varNode.InnerText = atmosphereDB.GreenhousePressure.ToString("N2");
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "HasHydrosphere", "NS");
                varNode.InnerText = atmosphereDB.Hydrosphere.ToString();
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "HydrosphereExtent", "NS");
                varNode.InnerText = atmosphereDB.HydrosphereExtent.ToString();
                bodyNode.AppendChild(varNode);
            }

            if (ruinsDB != null)
            {
                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "RuinCount", "NS");
                varNode.InnerText = ruinsDB.RuinCount.ToString();
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "RuinQuality", "NS");
                varNode.InnerText = ruinsDB.RuinQuality.ToString();
                bodyNode.AppendChild(varNode);

                varNode           = xmlDoc.CreateNode(XmlNodeType.Element, "RuinSize", "NS");
                varNode.InnerText = ruinsDB.RuinSize.ToString();
                bodyNode.AppendChild(varNode);
            }

            // add body node to system node:
            systemNode.AppendChild(bodyNode);

            // call recursively for children:
            foreach (var child in orbit.Children)
            {
                OrbitDB o = child.GetDataBlob <OrbitDB>();
                if (o != null)
                {
                    SerializeBodyToXML(xmlDoc, systemNode, o.OwningEntity, o);
                }
            }
        }
Example #4
0
        public static Entity CreateAsteroid4(Vector3 position, OrbitDB origOrbit, DateTime atDateTime, 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;
            }

            var     speed    = Distance.KmToAU(40);
            Vector3 velocity = new Vector3(speed, 0, 0);


            var massVolume  = MassVolumeDB.NewFromMassAndRadius_AU(mass, radius);
            var planetInfo  = new SystemBodyInfoDB();
            var name        = new NameDB("Ellie");
            var AsteroidDmg = new AsteroidDamageDB();

            AsteroidDmg.FractureChance = new PercentValue(0.75f);
            var dmgPfl     = EntityDamageProfileDB.AsteroidDamageProfile(massVolume.Volume_km3, massVolume.Density, massVolume.RadiusInM, 50);
            var sensorPfil = new SensorProfileDB();

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


            var parent     = origOrbit.Parent;
            var parentMass = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass     = massVolume.Mass;

            double sgp = GameConstants.Science.GravitationalConstant * (parentMass + myMass) / 3.347928976e33;
            //OrbitDB orbit = OrbitDB.FromVector(parent, myMass, parentMass, sgp, position, velocity, atDateTime);
            //OrbitDB orbit = (OrbitDB)origOrbit.Clone();
            OrbitDB orbit = new OrbitDB(origOrbit.Parent, parentMass, myMass, origOrbit.SemiMajorAxis_AU,
                                        origOrbit.Eccentricity, origOrbit.Inclination_Degrees, origOrbit.LongitudeOfAscendingNode_Degrees,
                                        origOrbit.ArgumentOfPeriapsis_Degrees, origOrbit.MeanMotion_DegreesSec, origOrbit.Epoch);

            var posDB = new PositionDB(position.X, position.Y, position.Z, parent.Manager.ManagerGuid, parent);


            var planetDBs = new List <BaseDataBlob>
            {
                posDB,
                massVolume,
                planetInfo,
                name,
                orbit,
                AsteroidDmg,
                dmgPfl,
                sensorPfil
            };

            Entity newELE = new Entity(origOrbit.OwningEntity.Manager, planetDBs);

            return(newELE);
        }
Example #5
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 < 0)
            {
                mass = 1.5e+12; //about 1.5 billion tonne
            }
            else
            {
                mass = asteroidMass;
            }

            var     speed    = 40000;
            Vector3 velocity = new Vector3(speed, 0, 0);


            var massVolume  = MassVolumeDB.NewFromMassAndRadius_AU(mass, radius);
            var planetInfo  = new SystemBodyInfoDB();
            var name        = new NameDB("Ellie");
            var AsteroidDmg = new AsteroidDamageDB();

            AsteroidDmg.FractureChance = new PercentValue(0.75f);
            var dmgPfl     = EntityDamageProfileDB.AsteroidDamageProfile(massVolume.Volume_km3, massVolume.Density, massVolume.RadiusInM, 50);
            var sensorPfil = new SensorProfileDB();

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

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


            var parent     = target.GetDataBlob <OrbitDB>().Parent;
            var parentMass = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass     = massVolume.Mass;

            double  sgp   = OrbitMath.CalculateStandardGravityParameterInM3S2(myMass, parentMass);
            OrbitDB orbit = OrbitDB.FromVector(parent, myMass, parentMass, sgp, targetPos, velocity, collisionDate);

            var currentpos = OrbitProcessor.GetAbsolutePosition_AU(orbit, StaticRefLib.CurrentDateTime);
            var posDB      = new PositionDB(currentpos.X, currentpos.Y, currentpos.Z, parent.Manager.ManagerGuid, parent);


            var planetDBs = new List <BaseDataBlob>
            {
                posDB,
                massVolume,
                planetInfo,
                name,
                orbit,
                AsteroidDmg,
                dmgPfl,
                sensorPfil
            };

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }
Example #6
0
        /// <summary>
        /// Generates an entire group of stars for a starSystem.
        /// </summary>
        /// <remarks>
        /// Stars created with this method are sorted by mass.
        /// Stars created with this method are added to the newSystem's EntityManager.
        /// </remarks>
        /// <param name="system">The Star System the new stars belongs to.</param>
        /// <param name="numStars">The number of stars to create.</param>
        /// <returns>A mass-sorted list of entity ID's for the generated stars.</returns>
        public List <Entity> CreateStarsForSystem(StarSystem system, int numStars, DateTime currentDateTime)
        {
            // Argument Validation.
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            if (numStars <= 0)
            {
                throw new ArgumentOutOfRangeException("numStars", "numStars must be greater than 0.");
            }

            // List of stars we'll be creating.
            var stars = new List <Entity>();

            while (stars.Count < numStars)
            {
                // Generate a SpectralType for the star.
                SpectralType starType;
                if (_galaxyGen.Settings.RealStarSystems)
                {
                    starType = _galaxyGen.Settings.StarTypeDistributionForRealStars.Select(system.RNG.NextDouble());
                }
                else
                {
                    starType = _galaxyGen.Settings.StarTypeDistributionForFakeStars.Select(system.RNG.NextDouble());
                }

                // We will use the one random number to select from all the spectral type ranges. Should give us saner numbers for stars.
                double randomSelection = system.RNG.NextDouble();

                // Generate the star's datablobs.
                MassVolumeDB starMVDB = MassVolumeDB.NewFromMassAndRadius(
                    GMath.SelectFromRange(_galaxyGen.Settings.StarMassBySpectralType[starType], randomSelection),
                    GMath.SelectFromRange(_galaxyGen.Settings.StarRadiusBySpectralType[starType], randomSelection));

                StarInfoDB starData = GenerateStarInfo(starMVDB, starType, randomSelection);

                // Initialize Position as 0,0,0. It will be updated when the star's orbit is calculated.
                PositionDB positionData = new PositionDB(0, 0, 0, system.Guid);

                var baseDataBlobs = new List <BaseDataBlob> {
                    starMVDB, starData, positionData
                };

                stars.Add(Entity.Create(system, Guid.Empty, baseDataBlobs));
            }

            // The root star must be the most massive. Find it.
            Entity rootStar = stars[0];

            double rootStarMass = rootStar.GetDataBlob <MassVolumeDB>().Mass;

            foreach (Entity currentStar in stars)
            {
                double currentStarMass = currentStar.GetDataBlob <MassVolumeDB>().Mass;

                if (rootStarMass < currentStarMass)
                {
                    rootStar     = currentStar;
                    rootStarMass = rootStar.GetDataBlob <MassVolumeDB>().Mass;
                }
            }

            // Swap the root star to index 0.
            int    rootIndex     = stars.IndexOf(rootStar);
            Entity displacedStar = stars[0];

            stars[rootIndex] = displacedStar;
            stars[0]         = rootStar;

            // Generate orbits.
            Entity       anchorStar   = stars[0];
            MassVolumeDB anchorMVDB   = anchorStar.GetDataBlob <MassVolumeDB>();
            Entity       previousStar = stars[0];

            previousStar.SetDataBlob(new OrbitDB());

            int starIndex = 0;

            foreach (Entity currentStar in stars)
            {
                StarInfoDB currentStarInfo   = currentStar.GetDataBlob <StarInfoDB>();
                NameDB     currentStarNameDB = new NameDB(system.NameDB.DefaultName + " " + (char)('A' + starIndex) + " " + currentStarInfo.SpectralType + currentStarInfo.SpectralSubDivision + currentStarInfo.LuminosityClass);
                currentStar.SetDataBlob(currentStarNameDB);

                if (previousStar == currentStar)
                {
                    // This is the "Anchor Star"
                    continue;
                }

                OrbitDB    previousOrbit    = previousStar.GetDataBlob <OrbitDB>();
                StarInfoDB previousStarInfo = previousStar.GetDataBlob <StarInfoDB>();

                double minDistance = _galaxyGen.Settings.OrbitalDistanceByStarSpectralType[previousStarInfo.SpectralType].Max + _galaxyGen.Settings.OrbitalDistanceByStarSpectralType[currentStarInfo.SpectralType].Max + previousOrbit.SemiMajorAxis;

                double sma          = minDistance * Math.Pow(system.RNG.NextDouble(), 3);
                double eccentricity = Math.Pow(system.RNG.NextDouble() * 0.8, 3);

                OrbitDB currentOrbit = OrbitDB.FromAsteroidFormat(anchorStar, anchorMVDB.Mass, currentStar.GetDataBlob <MassVolumeDB>().Mass, sma, eccentricity, _galaxyGen.Settings.MaxBodyInclination * system.RNG.NextDouble(), system.RNG.NextDouble() * 360, system.RNG.NextDouble() * 360, system.RNG.NextDouble() * 360, currentDateTime);
                currentStar.SetDataBlob(currentOrbit);
                currentStar.GetDataBlob <PositionDB>().SetParent(currentOrbit.Parent);
                previousStar = currentStar;
                starIndex++;
            }
            return(stars);
        }
Example #7
0
        /// <summary>
        /// PreciseOrbital Velocy in polar coordinates
        ///
        /// </summary>
        /// <returns>item1 is speed, item2 angle</returns>
        /// <param name="orbit">Orbit.</param>
        /// <param name="atDateTime">At date time.</param>
        public static (double speed, double heading) InstantaneousOrbitalVelocityPolarCoordinate(OrbitDB orbit, DateTime atDateTime)
        {
            var position = GetPosition_AU(orbit, atDateTime);
            var sma      = orbit.SemiMajorAxis_AU;

            if (orbit.GravitationalParameter_Km3S2 == 0 || sma == 0)
            {
                return(0, 0); //so we're not returning NaN;
            }
            var sgp = orbit.GravitationalParameterAU;

            double e           = orbit.Eccentricity;
            double trueAnomaly = GetTrueAnomaly(orbit, atDateTime);
            double aoP         = orbit.ArgumentOfPeriapsis;

            (double speed, double heading)polar = OrbitMath.ObjectLocalVelocityPolar(sgp, position, sma, e, trueAnomaly, aoP);

            return(polar);
        }
Example #8
0
 OrbitDB(OrbitDB toCopy, SensorInfoDB sensorInfo, Entity parentEntity) : base(parentEntity)
 {
     Epoch        = toCopy.Epoch; //This should stay the same
     IsStationary = toCopy.IsStationary;
     UpdateFromSensorInfo(toCopy, sensorInfo);
 }
Example #9
0
        /// <summary>
        /// This was designed so that fast moving objects will get interpolated a lot more than slow moving objects
        /// so fast moving objects shouldn't loose positional acuracy when close to a planet,
        /// and slow moving objects won't have processor time wasted on them by calulcating too often.
        /// However this seems to be unstable and looses energy, unsure why. currently set it to just itterate/interpolate every second.
        /// so currently will be using more time to get through this than neccisary.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="deltaSeconds">Delta seconds.</param>
        public static void NewtonMove(Entity entity, int deltaSeconds)
        {
            NewtonMoveDB          newtonMoveDB = entity.GetDataBlob <NewtonMoveDB>();
            NewtonThrustAbilityDB newtonThrust = entity.GetDataBlob <NewtonThrustAbilityDB>();
            PositionDB            positionDB   = entity.GetDataBlob <PositionDB>();
            double mass_Kg       = entity.GetDataBlob <MassVolumeDB>().Mass;
            double parentMass_kg = newtonMoveDB.ParentMass;

            var      manager        = entity.Manager;
            DateTime dateTimeFrom   = newtonMoveDB.LastProcessDateTime;
            DateTime dateTimeNow    = manager.ManagerSubpulses.StarSysDateTime;
            DateTime dateTimeFuture = dateTimeNow + TimeSpan.FromSeconds(deltaSeconds);
            double   deltaT         = (dateTimeFuture - dateTimeFrom).TotalSeconds;

            double secondsToItterate = deltaT;

            while (secondsToItterate > 0)
            {
                //double timeStep = Math.Max(secondsToItterate / speed_kms, 1);
                //timeStep = Math.Min(timeStep, secondsToItterate);
                double timeStepInSeconds  = 1;//because the above seems unstable and looses energy.
                double distanceToParent_m = positionDB.GetDistanceTo_m(newtonMoveDB.SOIParent.GetDataBlob <PositionDB>());

                distanceToParent_m = Math.Max(distanceToParent_m, 0.1); //don't let the distance be 0 (once collision is in this will likely never happen anyway)

                double  gravForce       = GameConstants.Science.GravitationalConstant * (mass_Kg * parentMass_kg / Math.Pow(distanceToParent_m, 2));
                Vector3 gravForceVector = gravForce * -Vector3.Normalise(positionDB.RelativePosition_m);

                Vector3 totalDVFromGrav = (gravForceVector / mass_Kg) * timeStepInSeconds;

                double maxAccelFromThrust1 = newtonThrust.ExhaustVelocity * Math.Log(mass_Kg / (mass_Kg - newtonThrust.FuelBurnRate)); //per second
                double maxAccelFromThrust  = newtonThrust.ThrustInNewtons / mass_Kg;                                                   //per second


                Vector3 manuverDV = newtonMoveDB.DeltaVForManuver_m;                      //how much dv needed to complete the manuver.

                double dryMass = mass_Kg - newtonThrust.FuelBurnRate * timeStepInSeconds; //how much our ship weighs after a timestep of fuel is used.
                //how much dv can we get in this timestep.
                double deltaVThisStep = OrbitMath.TsiolkovskyRocketEquation(mass_Kg, dryMass, newtonThrust.ExhaustVelocity);
                deltaVThisStep = Math.Min(manuverDV.Length(), deltaVThisStep);  //don't use more Dv than what is called for.
                deltaVThisStep = Math.Min(newtonThrust.DeltaV, deltaVThisStep); //check we've got the deltaV to spend.

                Vector3 totalDVFromThrust = Vector3.Normalise(manuverDV) * deltaVThisStep;

                //remove the deltaV we're expending from the max (TODO: Remove fuel from cargo, change mass of ship)
                newtonThrust.DeltaV -= deltaVThisStep;
                //remove the vectorDV from the amount needed to fully complete the manuver.
                newtonMoveDB.DeltaVForManuver_m -= totalDVFromThrust;



                Vector3 totalDV     = totalDVFromGrav + totalDVFromThrust;
                Vector3 newVelocity = totalDV + newtonMoveDB.CurrentVector_ms;

                newtonMoveDB.CurrentVector_ms = newVelocity;
                Vector3 deltaPos = (newtonMoveDB.CurrentVector_ms + newVelocity) / 2 * timeStepInSeconds;

                positionDB.RelativePosition_m += deltaPos;

                double sOIRadius = OrbitProcessor.GetSOI_m(newtonMoveDB.SOIParent);



                if (positionDB.RelativePosition_m.Length() >= sOIRadius)
                {
                    Entity  newParent;
                    Vector3 parentRalitiveVector;
                    //if our parent is a regular kepler object (normaly this is the case)
                    if (newtonMoveDB.SOIParent.HasDataBlob <OrbitDB>())
                    {
                        var orbitDB = newtonMoveDB.SOIParent.GetDataBlob <OrbitDB>();
                        newParent = orbitDB.Parent;
                        var parentVelocity = OrbitProcessor.InstantaneousOrbitalVelocityVector_m(orbitDB, entity.StarSysDateTime);
                        parentRalitiveVector = newtonMoveDB.CurrentVector_ms + parentVelocity;
                    }
                    else //if (newtonMoveDB.SOIParent.HasDataBlob<NewtonMoveDB>())
                    {   //this will pretty much never happen.
                        newParent = newtonMoveDB.SOIParent.GetDataBlob <NewtonMoveDB>().SOIParent;
                        var parentVelocity = newtonMoveDB.SOIParent.GetDataBlob <NewtonMoveDB>().CurrentVector_ms;
                        parentRalitiveVector = newtonMoveDB.CurrentVector_ms + parentVelocity;
                    }
                    parentMass_kg = newParent.GetDataBlob <MassVolumeDB>().Mass;

                    Vector3 posRalitiveToNewParent = positionDB.AbsolutePosition_m - newParent.GetDataBlob <PositionDB>().AbsolutePosition_m;


                    var    dateTime = dateTimeNow + TimeSpan.FromSeconds(deltaSeconds - secondsToItterate);
                    double sgp      = GMath.StandardGravitationalParameter(parentMass_kg + mass_Kg);
                    var    kE       = OrbitMath.KeplerFromPositionAndVelocity(sgp, posRalitiveToNewParent, parentRalitiveVector, dateTime);

                    positionDB.SetParent(newParent);
                    newtonMoveDB.ParentMass       = parentMass_kg;
                    newtonMoveDB.SOIParent        = newParent;
                    newtonMoveDB.CurrentVector_ms = parentRalitiveVector;
                }

                if (newtonMoveDB.DeltaVForManuver_m.Length() <= 0) //if we've completed the manuver.
                {
                    var    dateTime = dateTimeNow + TimeSpan.FromSeconds(deltaSeconds - secondsToItterate);
                    double sgp      = GMath.StandardGravitationalParameter(parentMass_kg + mass_Kg);

                    KeplerElements kE = OrbitMath.KeplerFromPositionAndVelocity(sgp, positionDB.RelativePosition_m, newtonMoveDB.CurrentVector_ms, dateTime);

                    var parentEntity = Entity.GetSOIParentEntity(entity, positionDB);

                    if (kE.Eccentricity < 1) //if we're going to end up in a regular orbit around our new parent
                    {
                        var newOrbit = OrbitDB.FromKeplerElements(
                            parentEntity,
                            mass_Kg,
                            kE,
                            dateTime);
                        entity.RemoveDataBlob <NewtonMoveDB>();
                        entity.SetDataBlob(newOrbit);
                        positionDB.SetParent(parentEntity);
                        var newPos = OrbitProcessor.GetPosition_m(newOrbit, dateTime);
                        positionDB.RelativePosition_m = newPos;
                    }
                    break;
                }

                secondsToItterate -= timeStepInSeconds;
            }
            newtonMoveDB.LastProcessDateTime = dateTimeFuture;
        }
Example #10
0
        /// <summary>
        /// PreciseOrbital Velocy in polar coordinates
        ///
        /// </summary>
        /// <returns>item1 is speed, item2 angle</returns>
        /// <param name="orbit">Orbit.</param>
        /// <param name="atDateTime">At date time.</param>
        public static (double speed, double angle) InstantaneousOrbitalVelocityPolarCoordinate(OrbitDB orbit, DateTime atDateTime)
        {
            var position = GetPosition_AU(orbit, atDateTime);
            var sma      = orbit.SemiMajorAxis;

            if (orbit.GravitationalParameter == 0 || sma == 0)
            {
                return(0, 0); //so we're not returning NaN;
            }
            var sgp = orbit.GravitationalParameterAU;

            double e = orbit.Eccentricity;

            double trueAnomaly = GetTrueAnomaly(orbit, atDateTime);
            double loAN        = Angle.ToRadians(orbit.LongitudeOfAscendingNode);
            double aoP         = Angle.ToRadians(orbit.ArgumentOfPeriapsis);
            double inclination = Angle.ToRadians(orbit.Inclination);
            var    loP         = OrbitMath.GetLongditudeOfPeriapsis(inclination, aoP, loAN);

            (double speed, double angle)polar = OrbitMath.InstantaneousOrbitalVelocityPolarCoordinate(sgp, position, sma, e, trueAnomaly);
            polar.angle += loP;
            return(polar);
        }
Example #11
0
        public static Entity DefaultHumans(Game game, string name)
        {
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, cargoInstalation);
            Entity colonySensor = FacPassiveSensor(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, colonySensor);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);


            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);


            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);

            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Entity ship1 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Touch-and-Go");
            var    fuel  = NameLookup.GetMaterialSD(game, "Sorium Fuel");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship3.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);



            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().Mass;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            Entity gunShip = ShipFactory.CreateShip(gunShipClass, solSys, factionEntity, earth, solSys, "Prevailing Stillness");

            gunShip.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            StorageSpaceProcessor.AddCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            //give the gunship a hypobolic orbit to test:
            var velInAU = Distance.KmToAU(25);

            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth)
            {
                CurrentVector_kms = new Vector3(0, -10.0, 0)
            };

            gunShip.SetDataBlob <NewtonMoveDB>(nmdb);

            Entity courier = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), solSys, factionEntity, earth, solSys, "Planet Express Ship");

            StorageSpaceProcessor.AddCargo(courier.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);

            solSys.SetDataBlob(ship1.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid3(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorReceverAtbDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                if (entityItem.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity != null) //don't do the designs, just the actual physical entity components.
                {
                    StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
                }
            }



            return(factionEntity);
        }
Example #12
0
        /// <summary>
        /// Creates our own solar system.
        /// This probibly needs to be Json! (since we're getting atmo stuff)
        /// Adds sol to game.StarSystems.
        /// </summary>
        public StarSystem CreateSol(Game game)
        {
            // WIP Function. Not complete.
            StarSystem sol = new StarSystem(game, "Sol", -1);

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

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

            SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true
            };
            MassVolumeDB mercuryMVDB         = MassVolumeDB.NewFromMassAndRadius(3.3022E23, Distance.KmToAU(2439.7));
            NameDB       mercuryNameDB       = new NameDB("Mercury");
            double       mercurySemiMajAxis  = 0.387098;
            double       mercuryEccentricity = 0.205630;
            double       mercuryInclination  = 0;
            double       mercuryLoAN         = 48.33167;
            double       mercuryLoP          = 77.45645;
            double       mercuryMeanLongd    = 252.25084;
            OrbitDB      mercuryOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, mercuryMVDB.Mass, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   mercuryPositionDB   = new PositionDB(OrbitProcessor.GetPosition(mercuryOrbitDB, game.CurrentDateTime), sol.Guid);
            Entity       mercury             = new Entity(sol.SystemManager, new List <BaseDataBlob> {
                mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury);

            SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true
            };
            MassVolumeDB venusMVDB         = MassVolumeDB.NewFromMassAndRadius(4.8676E24, Distance.KmToAU(6051.8));
            NameDB       venusNameDB       = new NameDB("Venus");
            double       venusSemiMajAxis  = 0.72333199;
            double       venusEccentricity = 0.00677323;
            double       venusInclination  = 0;
            double       venusLoAN         = 76.68069;
            double       venusLoP          = 131.53298;
            double       venusMeanLongd    = 181.97973;
            OrbitDB      venusOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, venusMVDB.Mass, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   venusPositionDB   = new PositionDB(OrbitProcessor.GetPosition(venusOrbitDB, game.CurrentDateTime), sol.Guid);
            Entity       venus             = new Entity(sol.SystemManager, new List <BaseDataBlob> {
                venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus);

            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true
            };
            MassVolumeDB earthMVDB         = MassVolumeDB.NewFromMassAndRadius(5.9726E24, Distance.KmToAU(6378.1));
            NameDB       earthNameDB       = new NameDB("Earth");
            double       earthSemiMajAxis  = 1.00000011;
            double       earthEccentricity = 0.01671022;
            double       earthInclination  = 0;
            double       earthLoAN         = -11.26064;
            double       earthLoP          = 102.94719;
            double       earthMeanLongd    = 100.46435;
            OrbitDB      earthOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, earthMVDB.Mass, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000);

            earthBodyDB.Tectonics = TectonicActivity.EarthLike;
            PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition(earthOrbitDB, game.CurrentDateTime), sol.Guid);
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f);
            AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 0.3f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?

            Entity earth = new Entity(sol.SystemManager, new List <BaseDataBlob> {
                earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB
            });

            _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth);

            SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Moon, SupportsPopulations = true
            };
            MassVolumeDB lunaMVDB         = MassVolumeDB.NewFromMassAndRadius(0.073E24, Distance.KmToAU(1738.14));
            NameDB       lunaNameDB       = new NameDB("Luna");
            double       lunaSemiMajAxis  = Distance.KmToAU(0.3844E6);
            double       lunaEccentricity = 0.0549;
            double       lunaInclination  = 5.1;
            // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively.
            // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression.
            double     lunaLoAN        = 125.08;
            double     lunaAoP         = 318.0634;
            double     lunaMeanAnomaly = 115.3654;
            OrbitDB    lunaOrbitDB     = OrbitDB.FromAsteroidFormat(earth, earthMVDB.Mass, lunaMVDB.Mass, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000);
            PositionDB lunaPositionDB  = new PositionDB(OrbitProcessor.GetPosition(lunaOrbitDB, game.CurrentDateTime), sol.Guid);
            Entity     luna            = new Entity(sol.SystemManager, new List <BaseDataBlob> {
                lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna);

            SystemBodyInfoDB marsBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true
            };
            MassVolumeDB marsMVDB         = MassVolumeDB.NewFromMassAndRadius(0.64174E24, Distance.KmToAU(3396.2));
            NameDB       marsNameDB       = new NameDB("Mars");
            double       marsSemiMajAxis  = Distance.KmToAU(227.92E6);
            double       marsEccentricity = 0.0934; //wiki says .0934
            double       marsInclination  = 1.85;
            double       marsLoAN         = 49.57854;
            double       marsAoP          = 336.04084;
            double       marsMeanLong     = 355.45332;
            OrbitDB      marsOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.Mass, marsMVDB.Mass, marsSemiMajAxis, marsEccentricity, marsInclination, marsLoAN, marsAoP, marsMeanLong, GalaxyGen.Settings.J2000);
            PositionDB   marsPositionDB   = new PositionDB(OrbitProcessor.GetPosition(marsOrbitDB, game.CurrentDateTime), sol.Guid);
            Entity       mars             = new Entity(sol.SystemManager, new List <BaseDataBlob> {
                marsPositionDB, marsBodyDB, marsMVDB, marsNameDB, marsOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mars);

            /*
             *
             * SystemBody Mars = new SystemBody(sun, SystemBody.PlanetType.Terrestrial);
             * Mars.Name = "Mars";
             * Mars.Orbit = Orbit.FromMajorPlanetFormat(0.64174E24, sun.Orbit.Mass, 1.52366231, 0.09341233, 1.85061, 49.57854, 336.04084, 355.45332, GalaxyGen.J2000);
             * Mars.Radius = Distance.ToAU(3396.2);
             * Mars.BaseTemperature = (float)CalculateBaseTemperatureOfBody(sun, Mars.Orbit.SemiMajorAxis);// 210.1f + (float)Constants.Units.KELVIN_TO_DEGREES_C;
             * Mars.Tectonics = SystemBody.TectonicActivity.Dead;
             * Mars.SurfaceGravity = 3.71f;
             * Mars.Atmosphere = new Atmosphere(Mars);
             * Mars.Atmosphere.Albedo = 0.250f;
             * Mars.Atmosphere.SurfaceTemperature = Mars.BaseTemperature;
             * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(12), 0.95f * 0.01f);  // C02% * Mars Atms
             * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(6), 0.027f * 0.01f);  // N% * Mars Atms
             * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(9), 0.007f * 0.01f);  // O% * Mars Atms
             * AddGasToAtmoSafely(Mars.Atmosphere, AtmosphericGas.AtmosphericGases.SelectAt(11), 0.016f * 0.01f);  // Ar% * Mars Atms
             * Mars.Atmosphere.UpdateState();
             * Mars.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Mars.Position.System = Sol;
             * Mars.Position.X = x;
             * Mars.Position.Y = y;
             * sun.Planets.Add(Mars);
             *
             * SystemBody Jupiter = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Jupiter.Name = "Jupiter";
             * Jupiter.Orbit = Orbit.FromMajorPlanetFormat(1898.3E24, sun.Orbit.Mass, 5.20336301, 0.04839266, 1.30530, 100.55615, 14.75385, 34.40438, GalaxyGen.J2000);
             * Jupiter.Radius = Distance.ToAU(71492);
             * Jupiter.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Jupiter.Position.System = Sol;
             * Jupiter.Position.X = x;
             * Jupiter.Position.Y = y;
             * sun.Planets.Add(Jupiter);
             *
             * SystemBody Saturn = new SystemBody(sun, SystemBody.PlanetType.GasGiant);
             * Saturn.Name = "Saturn";
             * Saturn.Orbit = Orbit.FromMajorPlanetFormat(568.36E24, sun.Orbit.Mass, 9.53707032, 0.05415060, 2.48446, 113.71504, 92.43194, 49.94432, GalaxyGen.J2000);
             * Saturn.Radius = Distance.ToAU(60268);
             * Saturn.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Saturn.Position.System = Sol;
             * Saturn.Position.X = x;
             * Saturn.Position.Y = y;
             * sun.Planets.Add(Saturn);
             *
             * SystemBody Uranus = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Uranus.Name = "Uranus";
             * Uranus.Orbit = Orbit.FromMajorPlanetFormat(86.816E24, sun.Orbit.Mass, 19.19126393, 0.04716771, 0.76986, 74.22988, 170.96424, 313.23218, GalaxyGen.J2000);
             * Uranus.Radius = Distance.ToAU(25559);
             * Uranus.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Uranus.Position.System = Sol;
             * Uranus.Position.X = x;
             * Uranus.Position.Y = y;
             * sun.Planets.Add(Uranus);
             *
             * SystemBody Neptune = new SystemBody(sun, SystemBody.PlanetType.IceGiant);
             * Neptune.Name = "Neptune";
             * Neptune.Orbit = Orbit.FromMajorPlanetFormat(102E24, sun.Orbit.Mass, Distance.ToAU(4495.1E6), 0.011, 1.8, 131.72169, 44.97135, 304.88003, GalaxyGen.J2000);
             * Neptune.Radius = Distance.ToAU(24764);
             * Neptune.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Neptune.Position.System = Sol;
             * Neptune.Position.X = x;
             * Neptune.Position.Y = y;
             * sun.Planets.Add(Neptune);
             *
             * SystemBody Pluto = new SystemBody(sun, SystemBody.PlanetType.DwarfPlanet);
             * Pluto.Name = "Pluto";
             * Pluto.Orbit = Orbit.FromMajorPlanetFormat(0.0131E24, sun.Orbit.Mass, Distance.ToAU(5906.38E6), 0.24880766, 17.14175, 110.30347, 224.06676, 238.92881, GalaxyGen.J2000);
             * Pluto.Radius = Distance.ToAU(1195);
             * Pluto.Orbit.GetPosition(GameState.Instance.CurrentDate, out x, out y);
             * Pluto.Position.System = Sol;
             * Pluto.Position.X = x;
             * Pluto.Position.Y = y;
             * sun.Planets.Add(Pluto);
             *
             * GenerateJumpPoints(Sol);
             *
             * // Clean up cached RNG:
             * m_RNG = null;
             * GameState.Instance.StarSystems.Add(Sol);
             * GameState.Instance.StarSystemCurrentIndex++;
             */

            JPSurveyFactory.GenerateJPSurveyPoints(sol);

            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            return(sol);
        }
Example #13
0
        public static Entity CreateAsteroid2(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 parent          = target.GetDataBlob <OrbitDB>().Parent;
            var parentMass      = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass          = massVolume.Mass;
            var mySemiMajorAxis = 5.055;
            var myEccentricity  = 0.8;
            var myInclination   = 0;
            var myLoAN          = 0;
            var myAoP           = -10;
            //var EccentricAnomaly = Math.Atan2()
            //var meanAnomaly =;
            double myLoP       = 0;
            double myMeanLongd = 355.5;
            //OrbitDB orbit = OrbitDB.FromAsteroidFormat(parent, parentMass, myMass, mySemiMajorAxis, myEccentricity, myInclination, myLoAN, myAoP, meanAnomaly, starSys.Game.CurrentDateTime);
            OrbitDB orbit = OrbitDB.FromMajorPlanetFormat(parent, parentMass, myMass, mySemiMajorAxis, myEccentricity, myInclination, myLoAN, myLoP, myMeanLongd, StaticRefLib.CurrentDateTime);

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

            Entity newELE = new Entity(starSys, planetDBs);

            return(newELE);
        }
Example #14
0
        /// <summary>
        /// Calculates a cartisian position for an intercept for a ship and an target's orbit.
        /// </summary>
        /// <returns>The intercept position and DateTime</returns>
        /// <param name="mover">The entity that is trying to intercept a target.</param>
        /// <param name="targetOrbit">Target orbit.</param>
        /// <param name="atDateTime">Datetime of transit start</param>
        public static (Vector3 position, DateTime etiDateTime) GetInterceptPosition_m(Entity mover, OrbitDB targetOrbit, DateTime atDateTime, Vector3 offsetPosition = new Vector3())
        {
            Vector3 moverPos = Entity.GetPosition_m(mover, atDateTime, false);
            double  spd_m    = mover.GetDataBlob <WarpAbilityDB>().MaxSpeed;

            return(OrbitMath.GetInterceptPosition_m(moverPos, spd_m, targetOrbit, atDateTime, offsetPosition));
        }
Example #15
0
        public StarSystem CreateTestSystem(Game game, int x = 0, int y = 0)
        {
            StarSystem sol = new StarSystem(game, "something", -1);

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

            sun.GetDataBlob <PositionDB>().X_AU += x;
            sun.GetDataBlob <PositionDB>().Y_AU += x;

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

            SystemBodyInfoDB mercuryBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.068f
            };                                                                                                                                      //Albedo = 0.068f
            MassVolumeDB mercuryMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(3.3022E23, Distance.KmToAU(2439.7));
            NameDB       mercuryNameDB       = new NameDB("LOLXDWTF");
            double       mercurySemiMajAxis  = 0.387098;
            double       mercuryEccentricity = 0.205630;
            double       mercuryInclination  = 0;
            double       mercuryLoAN         = 48.33167;
            double       mercuryLoP          = 77.45645;
            double       mercuryMeanLongd    = 252.25084;
            OrbitDB      mercuryOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, mercuryMVDB.MassDry, mercurySemiMajAxis, mercuryEccentricity, mercuryInclination, mercuryLoAN, mercuryLoP, mercuryMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   mercuryPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(mercuryOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            //AtmosphereDB mercuryAtmo = new AtmosphereDB();
            SensorProfileDB sensorProfile = new SensorProfileDB();

            mercuryPositionDB.X_AU += x;
            mercuryPositionDB.Y_AU += x;
            Entity mercury = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, mercuryPositionDB, mercuryBodyDB, mercuryMVDB, mercuryNameDB, mercuryOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, mercury);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, mercuryBodyDB, mercuryMVDB);

            SystemBodyInfoDB venusBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.77f
            };
            MassVolumeDB venusMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(4.8676E24, Distance.KmToAU(6051.8));
            NameDB       venusNameDB       = new NameDB("AYLMAOROFL");
            double       venusSemiMajAxis  = 0.72333199;
            double       venusEccentricity = 0.00677323;
            double       venusInclination  = 0;
            double       venusLoAN         = 76.68069;
            double       venusLoP          = 131.53298;
            double       venusMeanLongd    = 181.97973;
            OrbitDB      venusOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, venusMVDB.MassDry, venusSemiMajAxis, venusEccentricity, venusInclination, venusLoAN, venusLoP, venusMeanLongd, GalaxyGen.Settings.J2000);
            PositionDB   venusPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(venusOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);

            sensorProfile = new SensorProfileDB();
            Entity venus = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, venusPositionDB, venusBodyDB, venusMVDB, venusNameDB, venusOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, venus);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, venusBodyDB, venusMVDB);

            SystemBodyInfoDB earthBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Terrestrial, SupportsPopulations = true, Albedo = 0.306f
            };
            MassVolumeDB earthMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(5.9726E24, Distance.KmToAU(6378.1));
            NameDB       earthNameDB       = new NameDB("OMG");
            double       earthSemiMajAxis  = 1.00000011;
            double       earthEccentricity = 0.01671022;
            double       earthInclination  = 0;
            double       earthLoAN         = -11.26064;
            double       earthLoP          = 102.94719;
            double       earthMeanLongd    = 100.46435;
            OrbitDB      earthOrbitDB      = OrbitDB.FromMajorPlanetFormat(sun, sunMVDB.MassDry, earthMVDB.MassDry, earthSemiMajAxis, earthEccentricity, earthInclination, earthLoAN, earthLoP, earthMeanLongd, GalaxyGen.Settings.J2000);

            earthBodyDB.Tectonics = TectonicActivity.EarthLike;
            PositionDB earthPositionDB = new PositionDB(OrbitProcessor.GetPosition_AU(earthOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun);
            Dictionary <AtmosphericGasSD, float> atmoGasses = new Dictionary <AtmosphericGasSD, float>();

            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(6), 0.78f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(9), 0.12f);
            atmoGasses.Add(game.StaticData.AtmosphericGases.SelectAt(11), 0.01f);
            AtmosphereDB earthAtmosphereDB = new AtmosphereDB(1f, true, 71, 1f, 1f, 57.2f, atmoGasses); //TODO what's our greenhouse factor an pressure?

            sensorProfile = new SensorProfileDB();
            Entity earth = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, earthPositionDB, earthBodyDB, earthMVDB, earthNameDB, earthOrbitDB, earthAtmosphereDB
            });

            _systemBodyFactory.HomeworldMineralGeneration(game.StaticData, sol, earth);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, earthBodyDB, earthMVDB);


            SystemBodyInfoDB lunaBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Moon, SupportsPopulations = true
            };
            MassVolumeDB lunaMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(0.073E24, Distance.KmToAU(1738.14));
            NameDB       lunaNameDB       = new NameDB("NOWAY");
            double       lunaSemiMajAxis  = Distance.KmToAU(0.3844E6);
            double       lunaEccentricity = 0.0549;
            double       lunaInclination  = 0;//5.1;
            // Next three values are unimportant. Luna's LoAN and AoP regress/progress by one revolution every 18.6/8.85 years respectively.
            // Our orbit code it not advanced enough to deal with LoAN/AoP regression/progression.
            double     lunaLoAN        = 125.08;
            double     lunaAoP         = 318.0634;
            double     lunaMeanAnomaly = 115.3654;
            OrbitDB    lunaOrbitDB     = OrbitDB.FromAsteroidFormat(earth, earthMVDB.MassDry, lunaMVDB.MassDry, lunaSemiMajAxis, lunaEccentricity, lunaInclination, lunaLoAN, lunaAoP, lunaMeanAnomaly, GalaxyGen.Settings.J2000);
            PositionDB lunaPositionDB  = new PositionDB(OrbitProcessor.GetPosition_AU(lunaOrbitDB, StaticRefLib.CurrentDateTime) + earthPositionDB.AbsolutePosition_AU, sol.Guid, earth);

            sensorProfile = new SensorProfileDB();
            Entity luna = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, lunaPositionDB, lunaBodyDB, lunaMVDB, lunaNameDB, lunaOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, luna);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, lunaBodyDB, lunaMVDB);


            SystemBodyInfoDB halleysBodyDB = new SystemBodyInfoDB {
                BodyType = BodyType.Comet, SupportsPopulations = false, Albedo = 0.04f
            };                                                                                                                                 //Albedo = 0.04f
            MassVolumeDB halleysMVDB         = MassVolumeDB.NewFromMassAndRadius_AU(2.2e14, Distance.KmToAU(11));
            NameDB       halleysNameDB       = new NameDB("ASSHOLE");
            double       halleysSemiMajAxis  = 17.834;                                                                                                     //AU
            double       halleysEccentricity = 0.96714;
            double       halleysInclination  = 180;                                                                                                        //162.26° note retrograde orbit.
            double       halleysLoAN         = 58.42;                                                                                                      //°
            double       halleysAoP          = 111.33;                                                                                                     //°
            double       halleysMeanAnomaly  = 38.38;                                                                                                      //°
            OrbitDB      halleysOrbitDB      = OrbitDB.FromAsteroidFormat(sun, sunMVDB.MassDry, halleysMVDB.MassDry, halleysSemiMajAxis, halleysEccentricity, halleysInclination, halleysLoAN, halleysAoP, halleysMeanAnomaly, new System.DateTime(1994, 2, 17));
            PositionDB   halleysPositionDB   = new PositionDB(OrbitProcessor.GetPosition_AU(halleysOrbitDB, StaticRefLib.CurrentDateTime), sol.Guid, sun); // + earthPositionDB.AbsolutePosition_AU, sol.ID);

            sensorProfile = new SensorProfileDB();
            Entity halleysComet = new Entity(sol, new List <BaseDataBlob> {
                sensorProfile, halleysPositionDB, halleysBodyDB, halleysMVDB, halleysNameDB, halleysOrbitDB
            });

            _systemBodyFactory.MineralGeneration(game.StaticData, sol, halleysComet);
            SensorProcessorTools.PlanetEmmisionSig(sensorProfile, halleysBodyDB, halleysMVDB);

            JPSurveyFactory.GenerateJPSurveyPoints(sol);

            game.GameMasterFaction.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            return(sol);
        }
Example #16
0
        /// <summary>
        /// Calculates a cartisian position for an intercept for a ship and an target's orbit.
        /// </summary>
        /// <returns>The intercept position and DateTime</returns>
        /// <param name="mover">The entity that is trying to intercept a target.</param>
        /// <param name="targetOrbit">Target orbit.</param>
        /// <param name="atDateTime">Datetime of transit start</param>
        public static (Vector3 position, DateTime etiDateTime) GetInterceptPosition(Entity mover, OrbitDB targetOrbit, DateTime atDateTime, Vector3 offsetPosition = new Vector3())
        {
            Vector3 moverPos;

            if (mover.HasDataBlob <OrbitDB>())
            {
                //moverPos = Distance.AuToMt(OrbitProcessor.GetAbsolutePosition_AU(mover.GetDataBlob<OrbitDB>(), atDateTime));
                moverPos = OrbitProcessor.GetAbsolutePosition_AU(mover.GetDataBlob <OrbitDB>(), atDateTime);
            }
            else
            {
                moverPos = mover.GetDataBlob <PositionDB>().AbsolutePosition_AU;
            }
            double spd  = mover.GetDataBlob <PropulsionAbilityDB>().MaximumSpeed_MS;
            var    spd1 = Distance.MToAU(spd);

            return(GetInterceptPosition2(moverPos, spd1, targetOrbit, atDateTime, offsetPosition));
        }
Example #17
0
        /// <summary>
        /// Creates on Orbit at current location from a given velocity
        /// </summary>
        /// <returns>The Orbit Does not attach the OrbitDB to the entity!</returns>
        /// <param name="parent">Parent. must have massdb</param>
        /// <param name="entity">Entity. must have massdb</param>
        /// <param name="velocity_m">Velocity in meters.</param>
        public static OrbitDB FromVelocity_m(Entity parent, Entity entity, Vector3 velocity_m, DateTime atDateTime)
        {
            var parentMass = parent.GetDataBlob <MassVolumeDB>().Mass;
            var myMass     = entity.GetDataBlob <MassVolumeDB>().Mass;

            //var epoch1 = parent.Manager.ManagerSubpulses.StarSysDateTime; //getting epoch from here is incorrect as the local datetime doesn't change till after the subpulse.

            //var parentPos = OrbitProcessor.GetAbsolutePosition_AU(parent.GetDataBlob<OrbitDB>(), atDateTime); //need to use the parent position at the epoch
            var posdb = entity.GetDataBlob <PositionDB>();

            posdb.SetParent(parent);
            var ralitivePos = posdb.RelativePosition_m;//entity.GetDataBlob<PositionDB>().AbsolutePosition_AU - parentPos;

            if (ralitivePos.Length() > OrbitProcessor.GetSOI_m(parent))
            {
                throw new Exception("Entity not in target SOI");
            }

            //var sgp = GameConstants.Science.GravitationalConstant * (myMass + parentMass) / 3.347928976e33;
            var sgp_m = GMath.StandardGravitationalParameter(myMass + parentMass);
            var ke_m  = OrbitMath.KeplerFromPositionAndVelocity(sgp_m, ralitivePos, velocity_m, atDateTime);


            OrbitDB orbit = new OrbitDB(parent)
            {
                SemiMajorAxis            = ke_m.SemiMajorAxis,
                Eccentricity             = ke_m.Eccentricity,
                Inclination              = ke_m.Inclination,
                LongitudeOfAscendingNode = ke_m.LoAN,
                ArgumentOfPeriapsis      = ke_m.AoP,
                MeanAnomalyAtEpoch       = ke_m.MeanAnomalyAtEpoch,
                Epoch = atDateTime,

                _parentMass = parentMass,
                _myMass     = myMass
            };

            orbit.CalculateExtendedParameters();

            var pos = OrbitProcessor.GetPosition_m(orbit, atDateTime);
            var d   = (pos - ralitivePos).Length();

            if (d > 1)
            {
                var e = new Event(atDateTime, "Positional difference of " + Stringify.Distance(d) + " when creating orbit from velocity");
                e.Entity     = entity;
                e.SystemGuid = entity.Manager.ManagerGuid;
                e.EventType  = EventType.Opps;
                //e.Faction =  entity.FactionOwner;
                StaticRefLib.EventLog.AddEvent(e);

                //other info:
                var keta  = Angle.ToDegrees(ke_m.TrueAnomalyAtEpoch);
                var obta  = Angle.ToDegrees(OrbitProcessor.GetTrueAnomaly(orbit, atDateTime));
                var tadif = Angle.ToDegrees(Angle.DifferenceBetweenRadians(keta, obta));
                var pos1  = OrbitProcessor.GetPosition_m(orbit, atDateTime);
                var pos2  = OrbitProcessor.GetPosition_m(orbit, ke_m.TrueAnomalyAtEpoch);
                var d2    = (pos1 - pos2).Length();
            }


            return(orbit);
        }
Example #18
0
        public static (Vector3 position, DateTime etiDateTime) GetInterceptPosition2(Vector3 moverPos, double speed, OrbitDB targetOrbit, DateTime atDateTime, Vector3 offsetPosition = new Vector3())
        {
            var    pos = moverPos;
            double tim = 0;



            var pl = new obit()
            {
                position = moverPos,
                T        = targetOrbit.OrbitalPeriod.TotalSeconds,
            };

            double a = targetOrbit.SemiMajorAxis * 2;



            Vector3 p;
            int     i;
            double  tt, t, dt, a0, a1, T;

            // find orbital position with min error (coarse)
            a1 = -1.0;
            dt = 0.01 * pl.T;


            for (t = 0; t < pl.T; t += dt)
            {
                p  = OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, atDateTime + TimeSpan.FromSeconds(t)); //pl.position(sim_t + t);                     // try time t
                p += offsetPosition;
                tt = Vector3.Magnitude(p - pos) / speed;                                                       //length(p - pos) / speed;
                a0 = tt - t; if (a0 < 0.0)
                {
                    continue;                                 // ignore overshoots
                }
                a0 /= pl.T;                                   // remove full periods from the difference
                a0 -= Math.Floor(a0);
                a0 *= pl.T;
                if ((a0 < a1) || (a1 < 0.0))
                {
                    a1  = a0;
                    tim = tt;
                }   // remember best option
            }
            // find orbital position with min error (fine)
            for (i = 0; i < 10; i++)                               // recursive increase of accuracy
            {
                for (a1 = -1.0, t = tim - dt, T = tim + dt, dt *= 0.1; t < T; t += dt)
                {
                    p  = OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, atDateTime + TimeSpan.FromSeconds(t)); //p = pl.position(sim_t + t);                     // try time t
                    p += offsetPosition;
                    tt = Vector3.Magnitude(p - pos) / speed;                                                       //tt = length(p - pos) / speed;
                    a0 = tt - t; if (a0 < 0.0)
                    {
                        continue;                                 // ignore overshoots
                    }
                    a0 /= pl.T;                                   // remove full periods from the difference
                    a0 -= Math.Floor(a0);
                    a0 *= pl.T;
                    if ((a0 < a1) || (a1 < 0.0))
                    {
                        a1  = a0;
                        tim = tt;
                    }   // remember best option
                }
            }
            // direction
            p  = OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, atDateTime + TimeSpan.FromSeconds(tim));//pl.position(sim_t + tim);
            p += offsetPosition;
            //dir = normalize(p - pos);
            return(p, atDateTime + TimeSpan.FromSeconds(tim));
        }
Example #19
0
        public static Entity DefaultHumans(Game game, string name)
        {
            //USE THIS TO TEST CODE
            //TESTING STUFFF
            //return completeTest(game, name);
            // while(true){

            //}
            //TESTING STUFF
            var log = StaticRefLib.EventLog;
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            Entity targetFaction = FactionFactory.CreateFaction(game, "OpFor");

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD       = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesigner   mineDesigner = new ComponentDesigner(mineSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     mineDesign   = mineDesigner.CreateDesign(factionEntity);


            ComponentTemplateSD RefinerySD       = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesigner   refineryDesigner = new ComponentDesigner(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     refinaryDesign   = refineryDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD labSD       = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesigner   labDesigner = new ComponentDesigner(labSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     labEntity   = labDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD facSD       = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesigner   facDesigner = new ComponentDesigner(facSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     facEntity   = facDesigner.CreateDesign(factionEntity);

            Scientist scientistEntity = CommanderFactory.CreateScientist(factionEntity, colonyEntity);

            colonyEntity.GetDataBlob <TeamsHousedDB>().AddTeam(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new ID("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.CheckRequrements(factionTech);

            DefaultThrusterDesign(game, factionEntity);
            F1ThrusterDesign(game, factionEntity);
            RaptorThrusterDesign(game, factionEntity);
            RS25ThrusterDesign(game, factionEntity);
            DefaultWarpDesign(game, factionEntity);
            DefaultFuelTank(game, factionEntity);
            LargeFuelTank(game, factionEntity);
            DefaultCargoInstalation(game, factionEntity);
            DefaultSimpleLaser(game, factionEntity);
            DefaultBFC(game, factionEntity);
            ShipDefaultCargoHold(game, factionEntity);
            ShipSmallCargo(game, factionEntity);
            ShipPassiveSensor(game, factionEntity);
            FacPassiveSensor(game, factionEntity);
            DefaultFisionReactor(game, factionEntity);
            DefaultBatteryBank(game, factionEntity);
            DefaultFragPayload(game, factionEntity);
            DefaultMissileSRB(game, factionEntity);
            DefaultMissileSensors(game, factionEntity);
            DefaultMissileTube(game, factionEntity);
            MissileDesign250(game, factionEntity);
            ShipSmallOrdnanceStore(game, factionEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, mineDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, refinaryDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, _fuelTank_1000);

            EntityManipulation.AddComponentToEntity(colonyEntity, _cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, _cargoInstalation);

            EntityManipulation.AddComponentToEntity(colonyEntity, _sensorInstalation);
            EntityManipulation.AddComponentToEntity(colonyEntity, ShipYard(factionEntity));
            EntityManipulation.AddComponentToEntity(colonyEntity, _ordnanceStore, 10);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);

            var earthCargo = colonyEntity.GetDataBlob <VolumeStorageDB>();

            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            var iron = NameLookup.GetMineralSD(game, "Iron");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(iron, 5000);

            var hydrocarbon = NameLookup.GetMineralSD(game, "Hydrocarbons");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(hydrocarbon, 5000);

            var stainless = NameLookup.GetMaterialSD(game, "Stainless Steel");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(iron, 1000);
            colonyEntity.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(_missile, 100);
            colonyEntity.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(_merlin, 5);

            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);

            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).ID);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).ID);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            ShipDesign shipDesign    = DefaultShipDesign(game, factionEntity);
            ShipDesign gunShipDesign = GunShipDesign(game, factionEntity);

            Entity gunShip0 = ShipFactory.CreateShip(gunShipDesign, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2    = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3    = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Touch-and-Go");
            Entity gunShip1 = ShipFactory.CreateShip(gunShipDesign, factionEntity, earth, solSys, "Prevailing Stillness");
            Entity courier  = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), factionEntity, earth, solSys, "Planet Express Ship");
            Entity starship = ShipFactory.CreateShip(SpaceXStarShip(game, factionEntity), factionEntity, earth, solSys, "SN10");
            var    fuel     = NameLookup.GetMaterialSD(game, "Sorium Fuel");
            var    rp1      = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");
            var    methalox = NameLookup.GetMaterialSD(game, "Methalox");
            var    hydrolox = NameLookup.GetMaterialSD(game, "Hydrolox");

            earthCargo.AddCargoByUnit(rp1, 10000);
            earthCargo.AddCargoByUnit(methalox, 10000);
            earthCargo.AddCargoByUnit(hydrolox, 10000);

            gunShip0.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            gunShip1.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            ship2.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            ship3.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            var count = courier.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(hydrolox, 50000);

            starship.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(methalox, 1200000);

            gunShip0.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(MissileDesign250(game, factionEntity), 20);
            gunShip1.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(MissileDesign250(game, factionEntity), 20);

            var elec = NameLookup.GetMaterialSD(game, "Electrical Energy");

            gunShip0.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;
            ship2.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]    = 2750;
            ship3.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]    = 2750;
            gunShip1.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;
            courier.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]  = 2750;


            Entity targetDrone0 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (10 * Math.PI / 180), "Target Drone0");
            Entity targetDrone1 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (22.5 * Math.PI / 180), "Target Drone1");
            Entity targetDrone2 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (45 * Math.PI / 180), "Target Drone2");

            targetDrone0.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone0");
            targetDrone1.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone1");
            targetDrone2.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone2");

            targetDrone1.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 1000);
            targetDrone2.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 1000);


            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(gunShip0);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship2);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship3);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(gunShip1);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(courier);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(starship);



            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().MassDry;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().MassDry, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().MassDry, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            gunShip1.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            //give the gunship a hypobolic orbit to test:
            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip1.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth, new Vector3(0, -10000.0, 0));

            gunShip1.SetDataBlob <NewtonMoveDB>(nmdb);



            solSys.SetDataBlob(gunShip0.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip1.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));


            var pow = solSys.GetAllEntitiesWithDataBlob <EnergyGenAbilityDB>();

            foreach (var entityItem in pow)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(EnergyGenProcessor)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorAbilityDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }
            return(factionEntity);
        }
Example #20
0
        /// <summary>
        /// This was designed so that fast moving objects will get interpolated a lot more than slow moving objects
        /// so fast moving objects shouldn't loose positional acuracy when close to a planet,
        /// and slow moving objects won't have processor time wasted on them by calulcating too often.
        /// However this seems to be unstable and looses energy, unsure why. currently set it to just itterate/interpolate every second.
        /// so currently will be using more time to get through this than neccisary.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="deltaSeconds">Delta seconds.</param>
        public static void NewtonMove(Entity entity, int deltaSeconds)
        {
            NewtonMoveDB newtonMoveDB  = entity.GetDataBlob <NewtonMoveDB>();
            PositionDB   positionDB    = entity.GetDataBlob <PositionDB>();
            double       Mass_Kg       = entity.GetDataBlob <MassVolumeDB>().Mass;
            double       ParentMass_kg = newtonMoveDB.ParentMass;

            var      manager        = entity.Manager;
            DateTime dateTimeFrom   = newtonMoveDB.LastProcessDateTime;
            DateTime dateTimeNow    = manager.ManagerSubpulses.StarSysDateTime;
            DateTime dateTimeFuture = dateTimeNow + TimeSpan.FromSeconds(deltaSeconds);
            double   deltaT         = (dateTimeFuture - dateTimeFrom).TotalSeconds;

            double secondsToItterate = deltaT;

            while (secondsToItterate > 0)
            {
                double speed_kms = newtonMoveDB.CurrentVector_kms.Length();


                //double timeStep = Math.Max(secondsToItterate / speed_kms, 1);
                //timeStep = Math.Min(timeStep, secondsToItterate);
                double timeStep           = 1;//because the above seems unstable and looses energy.
                double distanceToParent_m = Distance.AuToMt(positionDB.GetDistanceTo(newtonMoveDB.SOIParent.GetDataBlob <PositionDB>()));

                distanceToParent_m = Math.Max(distanceToParent_m, 0.1); //don't let the distance be 0 (once collision is in this will likely never happen anyway)

                double  gravForce       = GameConstants.Science.GravitationalConstant * (Mass_Kg * ParentMass_kg / Math.Pow(distanceToParent_m, 2));
                Vector3 gravForceVector = gravForce * -Vector3.Normalise(positionDB.RelativePosition_AU);
                double  distance        = Distance.AuToKm(positionDB.RelativePosition_AU).Length();
                Vector3 totalForce      = gravForceVector + newtonMoveDB.ThrustVector;

                Vector3 acceleration_mps = totalForce / Mass_Kg;
                Vector3 newVelocity      = (acceleration_mps * timeStep * 0.001) + newtonMoveDB.CurrentVector_kms;

                newtonMoveDB.CurrentVector_kms = newVelocity;
                Vector3 deltaPos = (newtonMoveDB.CurrentVector_kms + newVelocity) / 2 * timeStep;
                //Vector4 deltaPos = newtonMoveDB.CurrentVector_kms * timeStep;

                positionDB.RelativePosition_AU += Distance.KmToAU(deltaPos);

                double sOIRadius_AU = OrbitProcessor.GetSOI(newtonMoveDB.SOIParent);

                if (positionDB.RelativePosition_AU.Length() >= sOIRadius_AU)
                {
                    Entity  newParent;
                    Vector3 parentRalitiveVector;
                    //if our parent is a regular kepler object (normaly this is the case)
                    if (newtonMoveDB.SOIParent.HasDataBlob <OrbitDB>())
                    {
                        var orbitDB = newtonMoveDB.SOIParent.GetDataBlob <OrbitDB>();
                        newParent = orbitDB.Parent;
                        var parentVelocity = OrbitProcessor.InstantaneousOrbitalVelocityVector(orbitDB, entity.Manager.ManagerSubpulses.StarSysDateTime);
                        parentRalitiveVector = Distance.KmToAU(newtonMoveDB.CurrentVector_kms) + parentVelocity;
                        var pvlen = Distance.AuToKm(parentVelocity.Length());
                        var vlen  = newtonMoveDB.CurrentVector_kms.Length();
                        var rvlen = Distance.AuToKm(parentRalitiveVector.Length());
                    }
                    else //if (newtonMoveDB.SOIParent.HasDataBlob<NewtonMoveDB>())
                    {   //this will pretty much never happen.
                        newParent = newtonMoveDB.SOIParent.GetDataBlob <NewtonMoveDB>().SOIParent;
                        var parentVelocity = newtonMoveDB.SOIParent.GetDataBlob <NewtonMoveDB>().CurrentVector_kms;
                        parentRalitiveVector = Distance.KmToAU(newtonMoveDB.CurrentVector_kms + parentVelocity);
                    }
                    double  newParentMass          = newParent.GetDataBlob <MassVolumeDB>().Mass;
                    double  sgp                    = GameConstants.Science.GravitationalConstant * (newParentMass + Mass_Kg) / 3.347928976e33;
                    Vector3 posRalitiveToNewParent = positionDB.AbsolutePosition_AU - newParent.GetDataBlob <PositionDB>().AbsolutePosition_AU;

                    var dateTime = dateTimeNow + TimeSpan.FromSeconds(deltaSeconds - secondsToItterate);
                    var kE       = OrbitMath.KeplerFromPositionAndVelocity(sgp, posRalitiveToNewParent, parentRalitiveVector, dateTime);

                    if (kE.Eccentricity < 1) //if we're going to end up in a regular orbit around our new parent
                    {
                        /*
                         * var newOrbit = OrbitDB.FromKeplerElements(
                         *  newParent,
                         *  newParentMass,
                         *  Mass_Kg,
                         *  kE,
                         *  dateTime);
                         */
                        var newOrbit = OrbitDB.FromVector(newParent, entity, parentRalitiveVector, dateTime);
                        entity.RemoveDataBlob <NewtonMoveDB>();
                        entity.SetDataBlob(newOrbit);
                        positionDB.SetParent(newParent);
                        var currentPos = Distance.AuToKm(positionDB.RelativePosition_AU);
                        var newPos     = OrbitProcessor.GetPosition_AU(newOrbit, dateTime);
                        var newPosKM   = Distance.AuToKm(newPos);
                        positionDB.RelativePosition_AU = newPos;
                        break;
                    }
                    else //else we're in a hyperbolic trajectory around our new parent, so just coninue the newtonion move.
                    {
                        positionDB.SetParent(newParent);
                        newtonMoveDB.ParentMass = newParentMass;
                        newtonMoveDB.SOIParent  = newParent;
                    }
                }
                secondsToItterate -= timeStep;
            }
            newtonMoveDB.LastProcessDateTime = dateTimeFuture;
        }