Exemplo n.º 1
0
        public void Init()
        {
            _game = new TestGame();
            StaticDataManager.LoadData("Pulsar4x", _game.Game);  // TODO: Figure out correct directory
            _entityManager = _game.Game.GlobalManager;



            // Initialize gas dictionary - haven't found a good way to look up gases without doing this
            _gasDictionary = new Dictionary <string, AtmosphericGasSD>();

            foreach (WeightedValue <AtmosphericGasSD> atmos in _game.Game.StaticData.AtmosphericGases)
            {
                _gasDictionary.Add(atmos.Value.ChemicalSymbol, atmos.Value);
            }


            _planetsList = new List <Entity>();
            _planetsList.Add(_game.Earth);

            _speciesList = new List <Entity>();
            _speciesList.Add(_game.HumanSpecies);
            //_speciesList.Add(_game.GreyAlienSpecies);

            // Set up colonies
            // @todo: add more colonies, especially ones with multiple species in one colony


            ComponentTemplateSD infrastructureSD       = _game.Game.StaticData.ComponentTemplates[new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb")];
            ComponentDesigner   infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());

            EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesigner.CreateDesign(_game.HumanFaction));

            ReCalcProcessor.ReCalcAbilities(_game.EarthColony);
        }
Exemplo n.º 2
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;

            _engineSD    = _game.StaticData.ComponentTemplates[new Guid("E76BD999-ECD7-4511-AD41-6D0C59CA97E6")];
            engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);
            engineDesign.ComponentDesignAbilities[0].SetValueFromInput(5); //size = 25 power.
            //engineDesignDB.ComponentDesignAbilities[1]
            _engineComponent = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign);

            _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship");
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent);

            Vector4 pos = new Vector4(0, 0, 0, 0);

            _ship = ShipFactory.CreateShip(_shipClass, _starSystem.SystemManager, _faction, pos, _starSystem, "Serial Peacemaker");
            PropulsionDB propulsion = _ship.GetDataBlob <PropulsionDB>();
            ShipInfoDB   shipInfo   = _ship.GetDataBlob <ShipInfoDB>();

            //Change in component cloning makes the next line's assumption untrue
            //Assert.True(_ship.GetDataBlob<ComponentInstancesDB>().SpecificInstances.ContainsKey(_engineComponent));
            Assert.AreEqual(50, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);

            EntityManipulation.AddComponentToEntity(_ship, _engineComponent);
            Assert.AreEqual(75, propulsion.TotalEnginePower);
            Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed);
        }
Exemplo n.º 3
0
        public void OnConstructionComplete(Entity industryEntity, CargoStorageDB storage, Guid productionLine, IndustryJob batchJob, IConstrucableDesign designInfo)
        {
            var colonyConstruction = industryEntity.GetDataBlob <IndustryAbilityDB>();

            batchJob.NumberCompleted++;
            batchJob.ResourcesRequired = designInfo.ResourceCosts;

            batchJob.ProductionPointsLeft = designInfo.IndustryPointCosts;


            if (batchJob.InstallOn != null)
            {
                ComponentInstance specificComponent = new ComponentInstance((ComponentDesign)designInfo);
                if (batchJob.InstallOn == industryEntity || StorageSpaceProcessor.HasEntity(storage, batchJob.InstallOn.GetDataBlob <CargoAbleTypeDB>()))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddCargo(storage, (ComponentDesign)designInfo, 1);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.ProductionLines[productionLine].Jobs.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.ProductionLines[productionLine].Jobs.Add(batchJob);
                }
            }
        }
        /// <summary>
        /// Processes the major updates.
        /// </summary>
        public void Process()
        {
            // Main tasks that will process character's route ticks, updates, and (any required) resets.
            if ((DateTime.Now - this.majorUpdatesTime).TotalMilliseconds >= 600)
            {
                List <Npc>       npcs       = new List <Npc>(GameEngine.World.NpcManager.Spawns.Values);
                List <Character> characters = new List <Character>(GameEngine.World.CharacterManager.Characters.Values);
                this.majorUpdatesTime = DateTime.Now;

                // Renerate new random values.
                Npc.RegenerateRandom();

                Parallel.ForEach(characters, EntityManipulation.TickCharacter);
                Parallel.ForEach(npcs, EntityManipulation.TickNpc);
                Parallel.ForEach(characters, (c) => EntityManipulation.UpdateCharacter(c, characters, npcs));
                Parallel.ForEach(characters, EntityManipulation.ResetCharacter);
                Parallel.ForEach(npcs, EntityManipulation.ResetNpc);
            }

            // Heals character's running energy.
            if ((DateTime.Now - this.runningHealerTime).TotalMilliseconds >= 2000)
            {
                List <Character> characters = new List <Character>(GameEngine.World.CharacterManager.Characters.Values);
                this.runningHealerTime = DateTime.Now;
                Parallel.ForEach(characters, EntityManipulation.RestoreRunEnergy);
            }

            // Process events.
            GameEngine.Events.Process();
        }
Exemplo n.º 5
0
        public static void LaunchMissile(Entity launchingEntity, Entity targetEntity, MissileLauncherAtb launcherAtb, OrdnanceDesign missileDesign)
        {
            var     atDatetime = launchingEntity.Manager.StarSysDateTime;
            var     positionDB = launchingEntity.GetDataBlob <PositionDB>();
            Vector3 position   = positionDB.AbsolutePosition_m;

            var tgtEntityOrbit = targetEntity.GetDataBlob <OrbitDB>();

            //MissileLauncherAtb launcherAtb;
            CargoStorageDB cargo  = launchingEntity.GetDataBlob <CargoStorageDB>();
            int            numMis = (int)StorageSpaceProcessor.GetAmount(cargo, missileDesign);

            if (numMis < 1)
            {
                return;
            }
            double launchSpeed = launcherAtb.LaunchForce / missileDesign.Mass;

            //missileDesign.

            double burnTime = (missileDesign.WetMass - missileDesign.DryMass) / missileDesign.BurnRate;
            double dv       = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, missileDesign.DryMass, missileDesign.ExaustVelocity);
            double avgSpd   = launchSpeed + dv * 0.5;

            var tgtEstPos = OrbitMath.GetInterceptPosition_m(position, avgSpd, tgtEntityOrbit, atDatetime);

            Vector3 parentVelocity = Entity.GetVelocity_m(launchingEntity, launchingEntity.Manager.StarSysDateTime);

            Vector3 tgtEstVector   = tgtEstPos.position - position; //future target position
            Vector3 launchVelocity = parentVelocity + tgtEstVector;

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

            dataBlobs.Add((PositionDB)positionDB.Clone());

            var newMissile = Entity.Create(launchingEntity.Manager, launchingEntity.FactionOwner, dataBlobs);

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

            StorageSpaceProcessor.RemoveCargo(cargo, missileDesign, 1);
            var thrusting = new NewtonMoveDB(positionDB.Parent, launchVelocity);

            thrusting.ActionOnDateTime   = atDatetime;
            thrusting.DeltaVForManuver_m = Vector3.Normalise(tgtEstPos.position) * dv;
            newMissile.SetDataBlob(thrusting);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void TestShipCreation()
        {
            ComponentDesign engineDesign;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction);

            _engineSD    = NameLookup.GetTemplateSD(_game, "Engine");
            engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData);
            engineDesign.ComponentDesignAttributes[0].SetValueFromInput(5); //size = 25 power.

            _engineComponentDesign = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign);

            _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship");

            Assert.True(_shipClass.FactionOwner == _faction.Guid);


            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign);
            EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign);

            Vector3 pos = new Vector3(0, 0, 0);
            int     designEngineNumber = _shipClass.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid);

            Assert.AreEqual(2, designEngineNumber);
            _ship = ShipFactory.CreateShip(_shipClass, _starSystem, _faction, pos, _starSystem, "Serial Peacemaker");
            Assert.AreEqual(designEngineNumber, _ship.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid), "Number of engine components not the same as design");

            PropulsionAbilityDB propulsion = _ship.GetDataBlob <PropulsionAbilityDB>();
            ShipInfoDB          shipInfo   = _ship.GetDataBlob <ShipInfoDB>();

            Assert.AreEqual(500000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower");
            float tonnage1       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage1);

            Assert.AreEqual(expectedSpeed1, propulsion.MaximumSpeed_MS, "Incorrect Max Speed");

            EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign); //add second engine
            Assert.AreEqual(750000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower 2nd engine added");
            float tonnage2       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage2);

            Assert.AreEqual(expectedSpeed2, propulsion.MaximumSpeed_MS, "Incorrect Max Speed 2nd engine");
        }
Exemplo n.º 8
0
        private void testPlanetAndSpecies(Entity planet, Entity species)
        {
            long[] basePop = new long[] { 0, 5, 10, 100, 999, 1000, 10000, 100000, 10000000 };
            long[] infrastructureAmounts = new long[] { 0, 1, 5, 100 };
            Dictionary <Entity, long> newPop, returnedPop;

            int i, j, k;

            Guid infGUID = new Guid("08b3e64c-912a-4cd0-90b0-6d0f1014e9bb");
            ComponentTemplateSD infrastructureSD = _game.Game.StaticData.ComponentTemplates[infGUID];


            ComponentDesigner infrastructureDesigner = new ComponentDesigner(infrastructureSD, _game.HumanFaction.GetDataBlob <FactionTechDB>());
            ComponentDesign   infrastructureDesign   = infrastructureDesigner.CreateDesign(_game.HumanFaction);

            Dictionary <Entity, long> pop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;


            // Single iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);


                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    //var infrastuctures = _game.EarthColony.GetDataBlob<ComponentInstancesDB>().SpecificInstances[infrastructureEntity].Where(inf => inf.DesignEntity.HasDataBlob<LifeSupportAbilityDB>());

                    returnedPop = calcGrowthIteration(_game.EarthColony, newPop);
                    PopulationProcessor.GrowPopulation(_game.EarthColony);

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(returnedPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }


            // Multiple iteration growth test
            for (i = 0; i < infrastructureAmounts.Length; i++)
            {
                // Create a new colony with this planet and species, add infrastructure item to it
                _game.EarthColony = ColonyFactory.CreateColony(_game.HumanFaction, species, planet);

                // Add the correct number of infrastructure to the colony
                for (k = 0; k < infrastructureAmounts[i]; k++)
                {
                    EntityManipulation.AddComponentToEntity(_game.EarthColony, infrastructureDesign);
                }
                ReCalcProcessor.ReCalcAbilities(_game.EarthColony);

                for (j = 0; j < basePop.Length; j++)
                {
                    // set up population and infrastructure for each test
                    newPop = _game.EarthColony.GetDataBlob <ColonyInfoDB>().Population;

                    foreach (KeyValuePair <Entity, long> kvp in newPop.ToArray())
                    {
                        newPop[kvp.Key] = basePop[j];
                    }

                    for (k = 0; k < 10; k++)
                    {
                        newPop = calcGrowthIteration(_game.EarthColony, newPop);
                        PopulationProcessor.GrowPopulation(_game.EarthColony);
                    }

                    foreach (KeyValuePair <Entity, long> kvp in pop.ToArray())
                    {
                        Assert.AreEqual(newPop[kvp.Key], pop[kvp.Key]);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void TestShipCreation()
        {
            ComponentDesigner engineDesigner;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction);

            //_engineSD = NameLookup.GetTemplateSD(_game, "Alcubierre Warp Drive");
            //engineDesigner = new ComponentDesigner(_engineSD, _faction.GetDataBlob<FactionTechDB>());
            //engineDesigner.ComponentDesignAttributes["Size"].SetValueFromInput(5); //size = 25 power.



            //_engineComponentDesign = engineDesigner.CreateDesign(_faction);
            _engineComponentDesign = DefaultStartFactory.DefaultWarpDesign(_game, _faction);


            _shipClass = DefaultStartFactory.DefaultShipDesign(_game, _faction);
            _ship      = ShipFactory.CreateShip(_shipClass, _faction, _sol, _starSystem, "Testship");


            ComponentInstancesDB instancesdb = _ship.GetDataBlob <ComponentInstancesDB>();

            instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances1);
            int origionalEngineNumber = instances1.Count;



            WarpAbilityDB warpAbility = _ship.GetDataBlob <WarpAbilityDB>();
            ShipInfoDB    shipInfo    = _ship.GetDataBlob <ShipInfoDB>();

            WarpDriveAtb warpAtb   = _engineComponentDesign.GetAttribute <WarpDriveAtb>();
            double       warpPower = warpAtb.WarpPower;

            Assert.AreEqual(warpPower * origionalEngineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower");
            float tonnage1       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage1);

            Assert.AreEqual(expectedSpeed1, warpAbility.MaxSpeed, "Incorrect Max Speed");


            EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign);
            instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances2);
            int add2engineNumber = instances2.Count;

            Assert.AreEqual(origionalEngineNumber + 1, add2engineNumber);


            Assert.AreEqual(warpPower * add2engineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower 2nd engine added");
            float tonnage2       = _ship.GetDataBlob <ShipInfoDB>().Tonnage;
            int   expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage2);

            Assert.AreEqual(expectedSpeed2, warpAbility.MaxSpeed, "Incorrect Max Speed 2nd engine");


            var energydb  = _ship.GetDataBlob <EnergyGenAbilityDB>();
            var energyMax = energydb.EnergyStoreMax[energydb.EnergyType.ID];

            energydb.EnergyStored[energydb.EnergyType.ID] = energyMax;

            Assert.IsTrue(energyMax >= warpAbility.BubbleCreationCost, "Ship does not store enough energy for a succesfull warp bubble creation");

            Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), 0);

            var posDB     = _ship.GetDataBlob <PositionDB>();
            var ralpos    = posDB.RelativePosition_m;
            var targetPos = new Vector3(ralpos.X, ralpos.Y, ralpos.Z);

            targetPos.X += expectedSpeed2 * 60 * 60; //distance for an hours travel.
            WarpMoveCommand.CreateCommand(
                _game,
                _faction,
                _ship,
                _sol,
                targetPos,
                _ship.StarSysDateTime,
                new Vector3(0, 0, 0));

            Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), expectedSpeed2, 1.0E-15);
            // _game.GameLoop.Ticklength = TimeSpan.FromSeconds(1);
            //_game.GameLoop.TimeStep();
            StaticRefLib.ProcessorManager.GetProcessor <WarpMovingDB>().ProcessEntity(_ship, 1);
            var ralposNow = posDB.RelativePosition_m;
            var distance  = Math.Abs((ralpos - ralposNow).Length());

            Assert.AreEqual(distance, expectedSpeed2, 1.0E-15);
        }
Exemplo n.º 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.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);
        }
Exemplo n.º 11
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.
        }