コード例 #1
0
ファイル: OrbitTests.cs プロジェクト: UberWaffe/Pulsar4x
        public void TestOrbitEpoch()
        {
            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            double  parentMass = 1.989e30;
            double  objMass    = 2.2e+15;
            Vector3 position   = new Vector3()
            {
                X = 0.57
            };                                             //Halley's Comet at periapse aprox
            Vector3 velocity = new Vector3()
            {
                Y = Distance.KmToAU(54)
            };

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);
            double sgp          = GameConstants.Science.GravitationalConstant * (parentMass + objMass) / 3.347928976e33;

            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());
        }
コード例 #2
0
        /// <summary>
        /// Refreshes the properties of this ViewModel.
        ///
        /// If partialRefresh is set to true, the ViewModel will try to update only data changes during a pulse.
        /// </summary>
        public void Refresh(bool partialRefresh = false)
        {
            // Get up-to-date datablobs for this entity.
            PositionDB positionDB = _entity.GetDataBlob <PositionDB>();

            UpdateProperties(positionDB);

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

            UpdateProperties(systemBodyDB, partialRefresh);

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

            UpdateProperties(nameDB);

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

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

                MassVolumeDB massVolumeDB = _entity.GetDataBlob <MassVolumeDB>();
                UpdateProperties(massVolumeDB);
            }
        }
コード例 #3
0
        public void TestOrbitEpoch()
        {
            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            double  parentMass = 1.989e30;
            double  objMass    = 2.2e+15;
            Vector3 position   = new Vector3()
            {
                X = Distance.AuToMt(0.57)
            };                                                              //Halley's Comet at periapse aprox
            Vector3 velocity = new Vector3()
            {
                Y = 54000
            };

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);
            double sgp_m        = OrbitMath.CalculateStandardGravityParameterInM3S2(parentMass, objMass);

            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp_m, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());
        }
コード例 #4
0
        void Setup(Entity entity)
        {
            _systemBodyInfoDB = entity.GetDataBlob <SystemBodyInfoDB>();
            _bodyType         = _systemBodyInfoDB.BodyType;
            _massVolDB        = entity.GetDataBlob <MassVolumeDB>();

            _rng = new Random(entity.Guid.GetHashCode()); //use entity guid as a seed for psudoRandomness.

            switch (_bodyType)
            {
            case BodyType.Asteroid:
                Asteroid();
                break;

            case BodyType.Terrestrial:
                Terestrial();
                break;

            default:
                Unknown();
                break;
            }

            if (entity.HasDataBlob <AtmosphereDB>())
            {
            }
        }
コード例 #5
0
ファイル: OrbitTests.cs プロジェクト: UberWaffe/Pulsar4x
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[3];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs1[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity     objEntity1 = new Entity(mgr, objBlobs1);
            PositionDB pos2       = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 8.52699302490434E-05, Z = 0
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[3];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                Mass = 10000
            };
            objBlobs2[2] = new NewtonMoveDB(parentEntity)
            {
                CurrentVector_kms = new Vector3(-10.0, 0, 0)
            };
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = Distance.AuToKm(pos1.AbsolutePosition_AU.Length());
            var distance2 = Distance.AuToKm(pos2.AbsolutePosition_AU.Length());

            //this test is currently failing and I'm unsure why. right now the code is using a 1s timestep so it should come out exact...
            //it looks ok graphicaly though so I'm not *too* conserned about this one right now.
            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }
コード例 #6
0
        private void UpdateProperties([NotNull] MassVolumeDB massVolumeDB)
        {
            if (massVolumeDB == null)
            {
                throw new ArgumentNullException("massVolumeDB");
            }

            Mass           = massVolumeDB.Mass;
            Density        = massVolumeDB.Density;
            Radius         = massVolumeDB.Radius;
            Volume         = massVolumeDB.Volume;
            SurfaceGravity = massVolumeDB.SurfaceGravity;
        }
コード例 #7
0
        public static Entity BasicSol(EntityManager mgr)
        {
            double parentMass = 1.989e30;

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            return(new Entity(mgr, parentblobs));
        }
コード例 #8
0
ファイル: Scene.cs プロジェクト: zenosisalive/Pulsar4x
        }                                                                                                                  //TODO fix this.use different units for display?



        #endregion TODO move to View



        public SystemObjectRenderInfo(Entity systemObjectEntity)
        {
            _systemObjectEntity = systemObjectEntity;

            _positionDB   = systemObjectEntity.GetDataBlob <PositionDB>();
            _massVolumeDB = systemObjectEntity.GetDataBlob <MassVolumeDB>();

            if (systemObjectEntity.HasDataBlob <StarInfoDB>())//is a star
            {
                StarSetup(systemObjectEntity.GetDataBlob <StarInfoDB>());
            }
            else if (systemObjectEntity.HasDataBlob <SystemBodyInfoDB>())//is an object other than a star
            {
                Planetetup(systemObjectEntity.GetDataBlob <SystemBodyInfoDB>());
            }
        }
コード例 #9
0
ファイル: TestingUtilities.cs プロジェクト: mqrause/Pulsar4x
        public static Entity BasicEarth(EntityManager mgr)
        {
            double parentMass = 5.97237e24;

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(mgr.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            return(new Entity(mgr, parentblobs));
        }
コード例 #10
0
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.Mass, shipDesign.Volume);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>() && ship.HasDataBlob <CargoStorageDB>())
            {
                NewtonionMovementProcessor.CalcDeltaV(ship);
            }

            return(ship);
        }
コード例 #11
0
        public void TestIntercept()
        {
            double        myMass     = 10000;
            double        parentMass = 1.989e30; //solar mass.
            Game          game       = new Game();
            EntityManager mgr        = new EntityManager(game, false);

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(mgr.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(mgr, parentblobs);

            Vector3 currentPos_m = new Vector3 {
                X = Distance.AuToMt(-0.77473184638034), Y = Distance.AuToMt(0.967145228951685)
            };
            Vector3 currentVelocity_m = new Vector3 {
                Y = Distance.KmToM(40)
            };
            double nonNewtSpeed_m = Distance.KmToM(283.018);

            Vector3 targetObjPosition = new Vector3 {
                X = Distance.AuToMt(0.149246434443459), Y = Distance.AuToMt(-0.712107888348067)
            };
            Vector3 targetObjVelocity = new Vector3 {
                Y = Distance.KmToM(35)
            };


            double sgp_m = OrbitMath.CalculateStandardGravityParameterInM3S2(myMass, parentMass);
            //KeplerElements ke = OrbitMath.KeplerFromVelocityAndPosition(sgp, targetObjPosition, targetObjVelocity);

            var currentDateTime = new DateTime(2000, 1, 1);

            OrbitDB targetOrbit = OrbitDB.FromVector(parentEntity, myMass, parentMass, sgp_m, targetObjPosition, targetObjVelocity, currentDateTime);



            var intercept_m = OrbitMath.GetInterceptPosition_m(currentPos_m, nonNewtSpeed_m, targetOrbit, currentDateTime);

            var futurePos1_m = OrbitProcessor.GetAbsolutePosition_m(targetOrbit, intercept_m.Item2);

            var futurePos2_m = intercept_m.Item1;



            Assert.AreEqual(futurePos1_m.Length(), futurePos2_m.Length(), 0.01);
            Assert.AreEqual(futurePos1_m.X, futurePos2_m.X, 0.01);
            Assert.AreEqual(futurePos1_m.Y, futurePos2_m.Y, 0.01);
            Assert.AreEqual(futurePos1_m.Z, futurePos2_m.Z, 0.01);
            var time       = intercept_m.Item2 - currentDateTime;
            var distance_m = (currentPos_m - intercept_m.Item1).Length();
            var speed      = distance_m / time.TotalSeconds;
            var distb_m    = nonNewtSpeed_m * time.TotalSeconds;

            var timeb = distance_m / nonNewtSpeed_m;

            Assert.AreEqual(nonNewtSpeed_m, speed, 1.0e-4);

            var dif = distance_m - distb_m;

            Assert.AreEqual(distance_m, distb_m, 100.0, "Out by a difference of " + dif + " meters");
        }
コード例 #12
0
        public void TestOrbitDBFromVectors(double parentMass, double objMass, Vector3 position, Vector3 velocity)
        {
            double         angleΔ = 0.0000000001;
            double         sgp_m  = OrbitMath.CalculateStandardGravityParameterInM3S2(objMass, parentMass);
            KeplerElements ke     = OrbitMath.KeplerFromPositionAndVelocity(sgp_m, position, velocity, new DateTime());

            Game          game = new Game();
            EntityManager man  = new EntityManager(game, false);

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(man.ManagerGuid)
            {
                X_AU = 0, Y_AU = 0, Z_AU = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(man, parentblobs);


            OrbitDB objOrbit  = OrbitDB.FromVector(parentEntity, objMass, parentMass, sgp_m, position, velocity, new DateTime());
            Vector3 resultPos = OrbitProcessor.GetPosition_AU(objOrbit, new DateTime());

            //check LoAN
            var objLoAN        = objOrbit.LongitudeOfAscendingNode;
            var keLoAN         = ke.LoAN;
            var loANDifference = objLoAN - keLoAN;

            Assert.AreEqual(keLoAN, objLoAN, angleΔ);

            //check AoP
            var objAoP     = objOrbit.ArgumentOfPeriapsis;
            var keAoP      = ke.AoP;
            var difference = objAoP - keAoP;

            Assert.AreEqual(keAoP, objAoP, angleΔ);


            //check MeanAnomalyAtEpoch
            var objM0 = objOrbit.MeanAnomalyAtEpoch;
            var keM0  = ke.MeanAnomalyAtEpoch;

            Assert.AreEqual(keM0, objM0, angleΔ);
            Assert.AreEqual(objM0, OrbitMath.GetMeanAnomalyFromTime(objM0, objOrbit.MeanMotion_DegreesSec, 0), "meanAnomalyError");

            //checkEpoch
            var objEpoch = objOrbit.Epoch;
            var keEpoch  = ke.Epoch;

            Assert.AreEqual(keEpoch, objEpoch);



            //check EccentricAnomaly:
            var objE = (OrbitProcessor.GetEccentricAnomaly(objOrbit, objOrbit.MeanAnomalyAtEpoch_Degrees));
            //var keE =   (OrbitMath.Gete(position, ke.SemiMajorAxis, ke.LinearEccentricity, ke.AoP));

            /*
             * if (objE != keE)
             * {
             *  var dif = objE - keE;
             *  Assert.AreEqual(keE, objE, angleΔ);
             * }
             */
            //check trueAnomaly
            var orbTrueAnom         = OrbitProcessor.GetTrueAnomaly(objOrbit, new DateTime());
            var orbtaDeg            = Angle.ToDegrees(orbTrueAnom);
            var differenceInRadians = orbTrueAnom - ke.TrueAnomalyAtEpoch;
            var differenceInDegrees = Angle.ToDegrees(differenceInRadians);

            if (ke.TrueAnomalyAtEpoch != orbTrueAnom)
            {
                Vector3 eccentVector = OrbitMath.EccentricityVector(sgp_m, position, velocity);
                var     tacalc1      = OrbitMath.TrueAnomaly(eccentVector, position, velocity);
                var     tacalc2      = OrbitMath.TrueAnomaly(sgp_m, position, velocity);

                var diffa = differenceInDegrees;
                var diffb = Angle.ToDegrees(orbTrueAnom - tacalc1);
                var diffc = Angle.ToDegrees(orbTrueAnom - tacalc2);

                var ketaDeg = Angle.ToDegrees(tacalc1);
            }

            Assert.AreEqual(0, Angle.DifferenceBetweenRadians(ke.TrueAnomalyAtEpoch, orbTrueAnom), angleΔ,
                            "more than " + angleΔ + " radians difference, at " + differenceInRadians + " \n " +
                            "(more than " + Angle.ToDegrees(angleΔ) + " degrees difference at " + differenceInDegrees + ")" + " \n " +
                            "ke Angle: " + ke.TrueAnomalyAtEpoch + " obj Angle: " + orbTrueAnom + " \n " +
                            "ke Angle: " + Angle.ToDegrees(ke.TrueAnomalyAtEpoch) + " obj Angle: " + Angle.ToDegrees(orbTrueAnom));

            Assert.AreEqual(ke.Eccentricity, objOrbit.Eccentricity);
            Assert.AreEqual(ke.SemiMajorAxis, objOrbit.SemiMajorAxis);


            var lenke1 = ke.SemiMajorAxis * 2;
            var lenke2 = ke.Apoapsis + ke.Periapsis;

            Assert.AreEqual(lenke1, lenke2, 1.0E-10);
            var lendb1 = objOrbit.SemiMajorAxis_AU * 2;
            var lendb2 = objOrbit.Apoapsis_AU + objOrbit.Periapsis_AU;

            Assert.AreEqual(lendb1, lendb2, 1.0E-10);
            Assert.AreEqual(lenke1, lendb1, 1.0E-10);
            Assert.AreEqual(lenke2, lendb2, 1.0E-10);



            var ke_apkm   = Distance.AuToKm(ke.Apoapsis);
            var db_apkm   = Distance.AuToKm(objOrbit.Apoapsis_AU);
            var differnce = ke_apkm - db_apkm;

            Assert.AreEqual(ke.Apoapsis, objOrbit.Apoapsis_AU, 1.0E-10);
            Assert.AreEqual(ke.Periapsis, objOrbit.Periapsis_AU, 1.0E-10);

            Vector3 posKM    = Distance.AuToKm(position);
            Vector3 resultKM = Distance.AuToKm(resultPos);

            double  keslr       = EllipseMath.SemiLatusRectum(ke.SemiMajorAxis, ke.Eccentricity);
            double  keradius    = OrbitMath.RadiusAtAngle(ke.TrueAnomalyAtEpoch, keslr, ke.Eccentricity);
            Vector3 kemathPos   = OrbitMath.GetRalitivePosition(ke.LoAN, ke.AoP, ke.Inclination, ke.TrueAnomalyAtEpoch, keradius);
            Vector3 kemathPosKM = Distance.AuToKm(kemathPos);

            Assert.AreEqual(kemathPosKM.Length(), posKM.Length(), 0.01);

            Assert.AreEqual(posKM.Length(), resultKM.Length(), 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.X, resultKM.X, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.Y, resultKM.Y, 0.01, "TA: " + orbtaDeg);
            Assert.AreEqual(posKM.Z, resultKM.Z, 0.01, "TA: " + orbtaDeg);

            if (velocity.Z == 0)
            {
                Assert.IsTrue(ke.Inclination == 0);
                Assert.IsTrue(objOrbit.Inclination_Degrees == 0);
            }

            //var speedVectorAU = OrbitProcessor.PreciseOrbitalVector(sgp, position, ke.SemiMajorAxis);
            //var speedVectorAU2 = OrbitProcessor.PreciseOrbitalVector(objOrbit, new DateTime());
            //Assert.AreEqual(speedVectorAU, speedVectorAU2);
        }
コード例 #13
0
 void SetIconFor(MassVolumeDB db)
 {
     _radius = db.Radius;
 }
コード例 #14
0
ファイル: ShipFactory.cs プロジェクト: Moth-Tolias/Pulsar4x
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.MassPerUnit, shipDesign.VolumePerUnit);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            StaticDataStore   staticdata = StaticRefLib.StaticData;
            ComponentDesigner fireControlDesigner;
            ComponentDesign   integratedfireControl;


            ComponentTemplateSD bfcSD = staticdata.ComponentTemplates[new Guid("33fcd1f5-80ab-4bac-97be-dbcae19ab1a0")];

            fireControlDesigner      = new ComponentDesigner(bfcSD, ownerFaction.GetDataBlob <FactionTechDB>());
            fireControlDesigner.Name = "Bridge Computer Systems";
            fireControlDesigner.ComponentDesignAttributes["Range"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Tracking Speed"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Size vs Range"].SetValueFromInput(0);

            //return fireControlDesigner.CreateDesign(faction);
            integratedfireControl = fireControlDesigner.CreateDesign(ownerFaction);
            ownerFaction.GetDataBlob <FactionTechDB>().IncrementLevel(integratedfireControl.TechID);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            EntityManipulation.AddComponentToEntity(ship, integratedfireControl, 1);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>())
            {
                NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship);
            }



            return(ship);
        }
コード例 #15
0
ファイル: OrbitTests.cs プロジェクト: UberWaffe/Pulsar4x
        public void TestIntercept()
        {
            double        myMass     = 10000;
            double        parentMass = 1.989e30; //solar mass.
            Game          game       = new Game();
            EntityManager mgr        = new EntityManager(game, false);

            BaseDataBlob[] parentblobs = new BaseDataBlob[3];
            parentblobs[0] = new PositionDB(mgr.ManagerGuid)
            {
                X = 0, Y = 0, Z = 0
            };
            parentblobs[1] = new MassVolumeDB()
            {
                Mass = parentMass
            };
            parentblobs[2] = new OrbitDB();
            Entity parentEntity = new Entity(mgr, parentblobs);

            Vector3 currentPos = new Vector3 {
                X = -0.77473184638034, Y = 0.967145228951685
            };
            Vector3 currentVelocity = new Vector3 {
                Y = Distance.KmToAU(40)
            };
            double nonNewtSpeed = Distance.KmToAU(283.018);

            Vector3 targetObjPosition = new Vector3 {
                X = 0.149246434443459, Y = -0.712107888348067
            };
            Vector3 targetObjVelocity = new Vector3 {
                Y = Distance.KmToAU(35)
            };


            double sgp = GameConstants.Science.GravitationalConstant * (parentMass + myMass) / 3.347928976e33;
            //KeplerElements ke = OrbitMath.KeplerFromVelocityAndPosition(sgp, targetObjPosition, targetObjVelocity);

            var currentDateTime = new DateTime(2000, 1, 1);

            OrbitDB targetOrbit = OrbitDB.FromVector(parentEntity, myMass, parentMass, sgp, targetObjPosition, targetObjVelocity, currentDateTime);



            var intercept = InterceptCalcs.GetInterceptPosition2(currentPos, nonNewtSpeed, targetOrbit, currentDateTime);

            var futurePos1 = Distance.AuToKm(OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, intercept.Item2));

            var futurePos2 = Distance.AuToKm(intercept.Item1);



            Assert.AreEqual(futurePos1.Length(), futurePos2.Length(), 0.01);
            Assert.AreEqual(futurePos1.X, futurePos2.X, 0.01);
            Assert.AreEqual(futurePos1.Y, futurePos2.Y, 0.01);
            Assert.AreEqual(futurePos1.Z, futurePos2.Z, 0.01);
            var time = intercept.Item2 - currentDateTime;

            var distance   = (currentPos - intercept.Item1).Length();
            var distancekm = Distance.AuToKm(distance);

            var speed  = distance / time.TotalSeconds;
            var speed2 = distancekm / time.TotalSeconds;

            var distb   = nonNewtSpeed * time.TotalSeconds;
            var distbKM = Distance.AuToKm(distb);
            var timeb   = distance / nonNewtSpeed;

            Assert.AreEqual(nonNewtSpeed, speed, 1.0e-10);

            var dif = distancekm - distbKM;

            Assert.AreEqual(distancekm, distbKM, 0.25);
        }
コード例 #16
0
ファイル: OrbitTests.cs プロジェクト: Moth-Tolias/Pulsar4x
        public void TestNewtonTrajectory()
        {
            Game          game         = new Game();
            EntityManager mgr          = new EntityManager(game, false);
            Entity        parentEntity = TestingUtilities.BasicEarth(mgr);

            PositionDB pos1 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt1 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs1 = new BaseDataBlob[4];
            objBlobs1[0] = pos1;
            objBlobs1[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs1[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs1[3] = newt1;
            Entity objEntity1 = new Entity(mgr, objBlobs1);


            PositionDB pos2 = new PositionDB(mgr.ManagerGuid, parentEntity)
            {
                X_AU = 0, Y_AU = 8.52699302490434E-05, Z_AU = 0
            };
            var newt2 = new NewtonMoveDB(parentEntity, new Vector3(-10.0, 0, 0))
            {
                DeltaVForManuver_FoRO_m = new Vector3(0, 1, 0)
            };

            BaseDataBlob[] objBlobs2 = new BaseDataBlob[4];
            objBlobs2[0] = pos2;
            objBlobs2[1] = new MassVolumeDB()
            {
                MassDry = 10000
            };
            objBlobs2[2] = new NewtonThrustAbilityDB(mgr.ManagerGuid);
            objBlobs2[3] = newt2;
            Entity objEntity2 = new Entity(mgr, objBlobs2);

            var seconds = 100;

            for (int i = 0; i < seconds; i++)
            {
                NewtonionMovementProcessor.NewtonMove(objEntity1, 1);

                //this is a hacky way to allow us to increment each second,
                //since the above method looks at the manager datetime and we're not updating that.
                newt1.LastProcessDateTime -= TimeSpan.FromSeconds(1);
            }
            NewtonionMovementProcessor.NewtonMove(objEntity2, seconds);
            var distance1 = (pos1.RelativePosition_m.Length());
            var distance2 = (pos2.RelativePosition_m.Length());

            Assert.AreEqual(distance1, distance2); //if we put the variable timstep which is related to the speed of the object in we'll have to give this a delta
        }
コード例 #17
0
        internal override void Display()
        {
            _isRunningFrame = true;
            if (IsActive)
            {
                SetFrameRateArray();
                if (ImGui.Begin("debug", ref IsActive))
                {
                    ImGui.Text(_state.PrimarySystemDateTime.ToString());
                    ImGui.Text("Cursor World Coordinate:");
                    var mouseWorldCoord = _state.Camera.MouseWorldCoordinate();
                    ImGui.Text("x" + mouseWorldCoord.X);
                    ImGui.SameLine();
                    ImGui.Text("y" + mouseWorldCoord.Y);

                    if (ImGui.CollapsingHeader("FrameRates", ImGuiTreeNodeFlags.CollapsingHeader))
                    {
                        //plot vars: (label, values, valueOffset, overlayText, scaleMin, scaleMax, graphSize, Stride)
                        //core game processing rate.
                        //ImGui.PlotHistogram("##GRHistogram", _gameRatesDisplay, 10, _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        //ImGui.PlotHistogram("##GRHistogram1", _gameRatesDisplay, 0 , _timeSpan.TotalSeconds.ToString(), 0, 1f, new ImVec2(0, 80), sizeof(float));
                        //string label, ref float values...
                        //ImGui.PlotHistogram(
                        ImGui.PlotHistogram("Game Tick ##GTHistogram", ref _gameRates[0], _gameRates.Length, _gameRateIndex, _currentGFPS.ToString(), 0f, largestGFPS, new Vector2(248, 60), sizeof(float));
                        ImGui.PlotLines("Game Tick ##GTPlotlines", ref _gameRates[0], _gameRates.Length, _gameRateIndex, _currentGFPS.ToString(), 0, largestGFPS, new Vector2(248, 60), sizeof(float));
                        //current star system processing rate.
                        ImGui.PlotHistogram("System Tick ##STHistogram", ref _systemRates[0], _systemRates.Length, _systemRateIndex, _currentSFPS.ToString(), 0f, 1f, new Vector2(248, 60), sizeof(float));
                        ImGui.PlotLines("System Tick ##STPlotlines", ref _systemRates[0], _systemRates.Length, _systemRateIndex, _currentSFPS.ToString(), 0, 1, new Vector2(248, 60), sizeof(float));
                        //ui framerate
                        ImGui.PlotHistogram("Frame Rate ##FPSHistogram", ref _frameRates[0], _frameRates.Length, _frameRateIndex, _currentFPS.ToString(), 0f, 10000, new Vector2(248, 60), sizeof(float));

                        foreach (var item in _systemState.StarSystem.ManagerSubpulses.ProcessTime)
                        {
                            ImGui.Text(item.Key.Name);
                            ImGui.SameLine();
                            ImGui.Text(item.Value.ToString());
                        }
                    }

                    if (ImGui.CollapsingHeader("GraphicTests", ImGuiTreeNodeFlags.CollapsingHeader))
                    {
                        var window = GraphicDebugWindow.GetWindow(_state);
                        window.Display();
                        window.Enable(true, _state);
                    }

                    ImGui.Text("Selected Star System: " + _state.SelectedStarSysGuid);
                    ImGui.Text("Number Of Entites: " + _state.SelectedSystem.NumberOfEntites);
                    if (ImGui.CollapsingHeader("Log"))
                    {
                        ImGui.BeginChild("LogChild", new Vector2(800, 300), true);
                        ImGui.Columns(4, "Events", true);
                        ImGui.Text("DateTime");
                        ImGui.NextColumn();
                        ImGui.Text("Faction");
                        ImGui.NextColumn();
                        ImGui.Text("Entity");
                        ImGui.NextColumn();
                        ImGui.Text("Event Message");
                        ImGui.NextColumn();

                        foreach (var gameEvent in StaticRefLib.EventLog.GetAllEvents())
                        {
                            string entityStr = "";
                            if (gameEvent.Entity != null)
                            {
                                if (gameEvent.Entity.HasDataBlob <NameDB>())
                                {
                                    entityStr = gameEvent.Entity.GetDataBlob <NameDB>().DefaultName;
                                }
                                else
                                {
                                    entityStr = gameEvent.Entity.Guid.ToString();
                                }
                            }
                            string factionStr = "";
                            if (gameEvent.Faction != null)
                            {
                                if (gameEvent.Faction.HasDataBlob <NameDB>())
                                {
                                    factionStr = gameEvent.Faction.GetDataBlob <NameDB>().DefaultName;
                                }
                                else
                                {
                                    factionStr = gameEvent.Faction.Guid.ToString();
                                }
                            }

                            ImGui.Separator();
                            ImGui.Text(gameEvent.Time.ToString());
                            ImGui.NextColumn();
                            ImGui.Text(factionStr);
                            ImGui.NextColumn();
                            ImGui.Text(entityStr);
                            ImGui.NextColumn();
                            ImGui.TextWrapped(gameEvent.Message);

                            ImGui.NextColumn();
                        }
                        //ImGui.Separator();
                        //ImGui.Columns();
                        ImGui.EndChild();
                    }
                    if (ImGui.CollapsingHeader("Entity List"))
                    {
                        List <Entity> factionOwnedEntites = _state.SelectedSystem.GetEntitiesByFaction(_state.Faction.Guid);
                        List <string> entityNames         = new List <string>();
                        foreach (var entity in factionOwnedEntites)
                        {
                            var name = entity.GetDataBlob <NameDB>();
                            if (name != null)
                            {
                                entityNames.Add(name.GetName(_state.Faction.Guid));
                            }
                        }
                        int item = 0;
                        ImGui.ListBox("Entites", ref item, entityNames.ToArray(), entityNames.Count);
                    }
                    if (_selectedEntityState != null && _selectedEntityState.Name != null && _selectedEntity.IsValid)
                    {
                        if (ImGui.CollapsingHeader("Selected Entity: " + _state.LastClickedEntity.Name + "###NameHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                        {
                            ImGui.Text(_state.LastClickedEntity.Entity.Guid.ToString());
                            if (_selectedEntity.HasDataBlob <PositionDB>())
                            {
                                var positiondb = _selectedEntity.GetDataBlob <PositionDB>();
                                var posv4      = positiondb.AbsolutePosition_AU;
                                ImGui.Text("x: " + posv4.X);
                                ImGui.Text("y: " + posv4.Y);
                                ImGui.Text("z: " + posv4.Z);
                                if (positiondb.Parent != null)
                                {
                                    ImGui.Text("Parent: " + positiondb.Parent.GetDataBlob <NameDB>().DefaultName);
                                    ImGui.Text("Dist: " + Distance.AuToKm(positiondb.RelativePosition_AU.Length()));
                                }
                            }
                            if (_selectedEntity.HasDataBlob <MassVolumeDB>())
                            {
                                if (ImGui.CollapsingHeader("MassVolumeDB: ###MassVolDBHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    MassVolumeDB mvdb = _selectedEntity.GetDataBlob <MassVolumeDB>();
                                    ImGui.Text("Mass " + mvdb.Mass + "Kg");
                                    ImGui.Text("Volume " + mvdb.Volume + "Km^3");
                                    ImGui.Text("Density " + mvdb.Density + "g/cm^3");
                                    ImGui.Text("Radius " + mvdb.Radius + "Km");
                                }
                            }
                            if (_selectedEntity.HasDataBlob <OrbitDB>())
                            {
                                if (ImGui.Checkbox("Draw SOI", ref _drawSOI))
                                {
                                    SimpleCircle cir;
                                    if (_drawSOI)
                                    {
                                        var soiradius = OrbitProcessor.GetSOI(_selectedEntity);
                                        var colour    = new SDL2.SDL.SDL_Color()
                                        {
                                            r = 0, g = 255, b = 0, a = 100
                                        };
                                        cir = new SimpleCircle(_selectedEntity.GetDataBlob <PositionDB>(), soiradius, colour);

                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(cir), cir);
                                    }
                                    else
                                    {
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(cir));
                                    }
                                }

                                if (ImGui.CollapsingHeader("OrbitDB: ###OrbitDBHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _selectedEntity.GetDataBlob <OrbitDB>();

                                    //if (_state.CurrentSystemDateTime != lastDate)
                                    //{
                                    pos        = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.PrimarySystemDateTime);
                                    truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.PrimarySystemDateTime);
                                    lastDate   = _state.PrimarySystemDateTime;
                                    //}

                                    ImGui.Text("x: " + pos.X);
                                    ImGui.Text("y: " + pos.Y);
                                    ImGui.Text("z: " + pos.Z);
                                    ImGui.Text("Eccentricity: " + orbitDB.Eccentricity);
                                    ImGui.Text("AoP:" + orbitDB.ArgumentOfPeriapsis);
                                    ImGui.Text("TrueAnomaly: " + truAnomoly);
                                    ImGui.Text("MeanMotion: " + orbitDB.MeanMotion + " in Deg/s");
                                    ImGui.Text("MeanVelocity: " + OrbitMath.MeanOrbitalVelocityInAU(orbitDB) + "Au/s");
                                    ImGui.Text("MeanVelocity: " + Distance.AuToKm(OrbitMath.MeanOrbitalVelocityInAU(orbitDB)) + "Km/s");
                                    ImGui.Text("SOI Radius: " + Distance.AuToKm(OrbitProcessor.GetSOI(_state.LastClickedEntity.Entity)));
                                    ImGui.Text("Orbital Period:" + orbitDB.OrbitalPeriod);
                                    ImGui.Text("SemiMajAxis: " + orbitDB.SemiMajorAxis);
                                    ImGui.Text("Periapsis: " + Distance.AuToKm(orbitDB.Periapsis).ToString("g3") + " Km");
                                    ImGui.Text("Appoapsis: " + Distance.AuToKm(orbitDB.Apoapsis).ToString("g3") + " Km");
                                    if (orbitDB.Parent != null)
                                    {
                                        ImGui.Text("Parent: " + orbitDB.Parent.GetDataBlob <NameDB>().DefaultName);
                                    }
                                    if (orbitDB.Children.Count > 0)
                                    {
                                        foreach (var item in orbitDB.Children)
                                        {
                                            ImGui.Text(item.GetDataBlob <NameDB>().DefaultName);
                                        }
                                    }
                                }
                            }

                            if (_selectedEntity.HasDataBlob <NewtonMoveDB>())
                            {
                                if (ImGui.Checkbox("Draw Parent SOI", ref _drawParentSOI))
                                {
                                    SimpleCircle psoi;
                                    SimpleLine   psoilin;
                                    if (_drawParentSOI)
                                    {
                                        var myPos  = _selectedEntity.GetDataBlob <PositionDB>();
                                        var parent = myPos.Parent;
                                        var pObt   = parent.GetDataBlob <OrbitDB>();
                                        var cnmve  = _selectedEntity.GetDataBlob <NewtonMoveDB>();

                                        var soiradius = OrbitProcessor.GetSOI(parent);
                                        var colour    = new SDL2.SDL.SDL_Color()
                                        {
                                            r = 0, g = 255, b = 0, a = 100
                                        };
                                        psoi = new SimpleCircle(parent.GetDataBlob <PositionDB>(), soiradius, colour);
                                        var pmass  = parent.GetDataBlob <MassVolumeDB>().Mass;
                                        var mymass = _selectedEntity.GetDataBlob <MassVolumeDB>().Mass;

                                        var    sgp          = GameConstants.Science.GravitationalConstant * (pmass + mymass) / 3.347928976e33;
                                        var    vel          = Distance.KmToAU(cnmve.CurrentVector_kms);
                                        var    cpos         = myPos.RelativePosition_AU;
                                        var    eccentVector = OrbitMath.EccentricityVector(sgp, cpos, vel);
                                        double ce           = eccentVector.Length();
                                        var    r            = cpos.Length();
                                        var    v            = vel.Length();

                                        var ca = 1 / (2 / r - Math.Pow(v, 2) / sgp);
                                        var cp = EllipseMath.SemiLatusRectum(ca, ce);

                                        var cAoP = Math.Atan2(eccentVector.Y, eccentVector.X);

                                        /*
                                         * var pa = pObt.SemiMajorAxis;
                                         * var pe = pObt.Eccentricity;
                                         * var pp = EllipseMath.SemiLatusRectum(pa, pe);
                                         */
                                        double θ = OrbitMath.AngleAtRadus(soiradius, cp, ce);
                                        θ += cAoP;

                                        var x = soiradius * Math.Cos(θ);
                                        var y = soiradius * Math.Sin(θ);
                                        psoilin = new SimpleLine(parent.GetDataBlob <PositionDB>(), new PointD()
                                        {
                                            X = x, Y = y
                                        }, colour);

                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(psoi), psoi);
                                        _state.SelectedSysMapRender.UIWidgets.Add(nameof(psoilin), psoilin);
                                    }
                                    else
                                    {
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(psoi));
                                        _state.SelectedSysMapRender.UIWidgets.Remove(nameof(psoilin));
                                    }
                                }
                            }

                            if (_state.LastClickedEntity.OrbitIcon != null)
                            {
                                if (ImGui.CollapsingHeader("OrbitIcon: ###OrbitIconHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    OrbitDB orbitDB = _selectedEntity.GetDataBlob <OrbitDB>();

                                    //string startRadian = _state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians.ToString();
                                    //string startDegrees = Angle.ToDegrees(_state.LastClickedEntity.OrbitIcon._ellipseStartArcAngleRadians).ToString();
                                    //ImGui.Text("StartAngleRadians: " + startRadian);
                                    //ImGui.Text("StartAngleDegrees: " + startDegrees);
                                    if (ImGui.CollapsingHeader("OrbitIconLines", ImGuiTreeNodeFlags.CollapsingHeader))
                                    {
                                        var window = OrbitalDebugWindow.GetWindow(_state.LastClickedEntity);
                                        window.Display();
                                        window.Enable(true, _state);
                                    }
                                }
                            }

                            if (_selectedEntity.HasDataBlob <PropulsionAbilityDB>())
                            {
                                if (ImGui.CollapsingHeader("Propulsion: ###PropulsionHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                {
                                    PropulsionAbilityDB propulsionDB = _selectedEntity.GetDataBlob <PropulsionAbilityDB>();
                                    ImGui.Text("NonNewt Engine Power: " + propulsionDB.TotalEnginePower);
                                    ImGui.Text("Max Speed: " + propulsionDB.MaximumSpeed_MS);
                                    ImGui.Text("CurrentVector: " + propulsionDB.CurrentVectorMS);
                                    ImGui.Text("Current Speed: " + ECSLib.Vector3.Magnitude(propulsionDB.CurrentVectorMS));
                                    if (_state.LastClickedEntity.Entity.HasDataBlob <CargoStorageDB>())
                                    {
                                        var fuelsGuid = propulsionDB.FuelUsePerKM;
                                        var storage   = _state.LastClickedEntity.Entity.GetDataBlob <CargoStorageDB>();
                                        foreach (var fuelItemGuid in fuelsGuid.Keys)
                                        {
                                            var fuel = _state.Game.StaticData.GetICargoable(fuelItemGuid);
                                            ImGui.Text(fuel.Name);
                                            ImGui.SameLine();
                                            ImGui.Text(StorageSpaceProcessor.GetAmount(storage, fuel).ToString());
                                        }
                                    }
                                }
                                if (_state.LastClickedEntity.Entity.HasDataBlob <TranslateMoveDB>())
                                {
                                    var db = _state.LastClickedEntity.Entity.GetDataBlob <TranslateMoveDB>();
                                    if (ImGui.CollapsingHeader("Transit: ###TransitHeader", ImGuiTreeNodeFlags.CollapsingHeader))
                                    {
                                        ImGui.Text("EntryPoint " + db.TranslateEntryPoint_AU);
                                        ImGui.Text("ExitPoint  " + db.TranslateExitPoint_AU);
                                        ImGui.Text("EDA " + db.PredictedExitTime.ToString());
                                        double distance = Distance.DistanceBetween(db.TranslateEntryPoint_AU, db.TranslateExitPoint_AU);
                                        ImGui.Text("Distance " + distance + " AU");
                                        ImGui.SameLine();
                                        double distancekm = Distance.AuToKm(distance);
                                        ImGui.Text(distancekm.ToString() + " KM");
                                        var timeToTarget = db.PredictedExitTime - _state.PrimarySystemDateTime;
                                        ImGui.Text("Remaining TTT " + timeToTarget);
                                        var totalTime = db.PredictedExitTime - db.EntryDateTime;
                                        ImGui.Text("Total TTT  " + totalTime);
                                        double speed = ((distancekm * 1000) / totalTime.TotalSeconds);
                                        ImGui.Text("speed2 " + speed);
                                        ImGui.Text("LastDateTime: ");
                                        ImGui.Text(db.LastProcessDateTime.ToString());
                                        ImGui.Text("Time Since Last: ");
                                        var timelen = _state.PrimarySystemDateTime - db.LastProcessDateTime;
                                        ImGui.Text(timelen.ToString());
                                    }
                                }
                            }
                            if (_selectedEntity.HasDataBlob <SensorInfoDB>())
                            {
                                var actualEntity = _selectedEntity.GetDataBlob <SensorInfoDB>().DetectedEntity;
                                if (actualEntity.IsValid && actualEntity.HasDataBlob <AsteroidDamageDB>())
                                {
                                    var dmgDB = actualEntity.GetDataBlob <AsteroidDamageDB>();
                                    ImGui.Text("Remaining HP: " + dmgDB.Health.ToString());
                                }
                            }
                        }
                    }
                }
                //else IsActive = false;
                ImGui.End();
            }
            _isRunningFrame           = false;
            _dateChangeSinceLastFrame = false;
        }
コード例 #18
0
        public static void LaunchMissile(Entity launchingEntity, Entity targetEntity, double launchForce, OrdnanceDesign missileDesign, int count)
        {
            var     atDatetime       = launchingEntity.Manager.StarSysDateTime;
            var     parentPositionDB = launchingEntity.GetDataBlob <PositionDB>();
            Vector3 parentPosition   = parentPositionDB.AbsolutePosition_m;
            var     parentPosRal     = parentPositionDB.RelativePosition_m;
            var     tgtEntityOrbit   = targetEntity.GetDataBlob <OrbitDB>();

            if (targetEntity.HasDataBlob <OrbitUpdateOftenDB>())
            {
                tgtEntityOrbit = targetEntity.GetDataBlob <OrbitUpdateOftenDB>();
            }

            //MissileLauncherAtb launcherAtb;
            VolumeStorageDB cargo = launchingEntity.GetDataBlob <VolumeStorageDB>();

            int numMis = cargo.TypeStores[missileDesign.CargoTypeID].CurrentStoreInUnits[missileDesign.ID];

            if (numMis < 1)
            {
                return;
            }



            double launchSpeed = launchForce / missileDesign.MassPerUnit;

            double  burnTime        = ((missileDesign.WetMass - missileDesign.DryMass) / missileDesign.BurnRate) * 0.8; //use 80% of fuel.
            double  drymass         = (missileDesign.WetMass - missileDesign.DryMass) * 0.8;                            //use 80% of fuel.
            double  launchManuverDv = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, drymass, missileDesign.ExaustVelocity);
            double  totalDV         = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, missileDesign.DryMass, missileDesign.ExaustVelocity);
            double  speed           = launchSpeed + launchManuverDv;
            var     misslPositionDB = (PositionDB)parentPositionDB.Clone();
            Vector3 parentVelocity  = Entity.GetRalitiveFutureVelocity(launchingEntity, launchingEntity.StarSysDateTime);



            var orderabledb = new OrderableDB();
            var newtmovedb  = new NewtonMoveDB(misslPositionDB.Parent, parentVelocity);

            string defaultName  = "Missile";
            string factionsName = missileDesign.Name;

            if (count > 1)
            {
                defaultName  += " x" + count;
                factionsName += " x" + count;
            }

            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            dataBlobs.Add(new ProjectileInfoDB(launchingEntity.Guid, count));
            dataBlobs.Add(new ComponentInstancesDB());
            dataBlobs.Add(misslPositionDB);
            dataBlobs.Add(MassVolumeDB.NewFromMassAndVolume(missileDesign.WetMass, missileDesign.WetMass));
            dataBlobs.Add(new NameDB(defaultName, launchingEntity.FactionOwner, factionsName));
            dataBlobs.Add(newtmovedb);
            dataBlobs.Add(orderabledb);
            var newMissile = Entity.Create(launchingEntity.Manager, launchingEntity.FactionOwner, dataBlobs);

            foreach (var tuple in missileDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(newMissile, tuple.design, tuple.count);
            }

            var newtdb = newMissile.GetDataBlob <NewtonThrustAbilityDB>();

            newtdb.DryMass_kg = missileDesign.MassPerUnit;
            newtdb.SetFuel(missileDesign.WetMass - missileDesign.MassPerUnit);


            bool directAttack = false;


            if (directAttack)
            {
                /*
                 * var tgtintercept = OrbitMath.GetInterceptPosition_m(parentPosition, speed, tgtEntityOrbit, atDatetime);
                 * var tgtEstPos = tgtintercept.position + targetEntity.GetDataBlob<PositionDB>().RelativePosition_m;
                 *
                 * var tgtCurPos = Entity.GetPosition_m(targetEntity, atDatetime);
                 *
                 * var vectorToTgt = Vector3.Normalise(tgtCurPos - parentPosRal);
                 *
                 * //var vectorToTgt = Vector3.Normalise(tgtEstPos - parentPosRal);
                 * var launcherVector = vectorToTgt * launchSpeed;
                 *
                 *
                 * var launchVelocity = parentVelocity + launcherVector;
                 * var manuverDV = vectorToTgt * launchManuverDv;
                 *
                 * launchVelocity = parentVelocity + launcherVector;
                 */
                ThrustToTargetCmd.CreateCommand(launchingEntity.FactionOwner, newMissile, launchingEntity.StarSysDateTime, targetEntity);
            }
            else
            {
                var launchOrbit = launchingEntity.GetDataBlob <OrbitDB>();
                if (launchingEntity.HasDataBlob <OrbitUpdateOftenDB>())
                {
                    launchOrbit = launchingEntity.GetDataBlob <OrbitUpdateOftenDB>();
                }

                var launchTrueAnomaly = OrbitProcessor.GetTrueAnomaly(launchOrbit, atDatetime);
                var targetTrueAnomaly = OrbitProcessor.GetTrueAnomaly(tgtEntityOrbit, atDatetime);
                var phaseAngle        = targetTrueAnomaly - launchTrueAnomaly;
                var manuvers          = InterceptCalcs.OrbitPhasingManuvers(launchOrbit, atDatetime, phaseAngle);


                var manuverDV = manuvers[0].deltaV;
                //newtmovedb.ActionOnDateTime = atDatetime;
                //newtmovedb.DeltaVForManuver_FoRO_m = manuverDV;
                NewtonThrustCommand.CreateCommand(launchingEntity.FactionOwner, newMissile, atDatetime, manuverDV);

                DateTime futureDate = atDatetime + TimeSpan.FromSeconds(manuvers[1].timeInSeconds);
                Vector3  futureDV   = manuvers[1].deltaV;
                NewtonThrustCommand.CreateCommand(launchingEntity.FactionOwner, newMissile, futureDate, futureDV);
                //ThrustToTargetCmd.CreateCommand(launchingEntity.FactionOwner, newMissile, futureDate + TimeSpan.FromSeconds(1), targetEntity);
            }

            cargo.RemoveCargoByUnit(missileDesign, 1); //remove missile from parent.
        }