コード例 #1
0
ファイル: NavWindow.cs プロジェクト: Moth-Tolias/Pulsar4x
        void DisplayPhaseChangeMode()
        {
            ImGui.SliderAngle("PhaseAngle", ref _phaseAngleRadians);

            var manuvers = InterceptCalcs.OrbitPhasingManuvers(_currentKE, _sgp, _atDatetime, _phaseAngleRadians);


            double totalManuverDV = 0;

            foreach (var manuver in manuvers)
            {
                ImGui.Text(manuver.deltaV.Length() + "Δv");
                totalManuverDV += manuver.deltaV.Length();
                ImGui.Text("Seconds: " + manuver.timeInSeconds);
            }

            ImGui.Text("Total Δv");
            ImGui.SameLine();
            ImGui.Text("for all manuvers: " + Stringify.Velocity(totalManuverDV));



            if (ImGui.Button("Make it so"))
            {
                NewtonThrustCommand.CreateCommand(_orderEntity.FactionOwner, _orderEntity, _atDatetime, manuvers[0].deltaV);
                DateTime futureDate = _atDatetime + TimeSpan.FromSeconds(manuvers[1].timeInSeconds);
                NewtonThrustCommand.CreateCommand(_orderEntity.FactionOwner, _orderEntity, futureDate, manuvers[1].deltaV);
            }
        }
コード例 #2
0
        void ActionCmd()
        {
            NewtonThrustCommand.CreateCommand(
                _uiState.Faction.Guid,
                OrderingEntity.Entity,
                _actionDateTime,
                _deltaV_MS);

            CloseWindow();
        }
コード例 #3
0
ファイル: NavWindow.cs プロジェクト: Moth-Tolias/Pulsar4x
        void DisplayHohmannMode()
        {
            double mySMA  = _currentKE.SemiMajorAxis;
            float  smaMin = 1;
            float  smaMax = (float)OrbitProcessor.GetSOI_m(Entity.GetSOIParentEntity(_orderEntity));

            if (ImGui.Combo("Target Object", ref _selectedSibling, _siblingNames, _siblingNames.Length))
            {
                Entity selectedSib = _siblingEntities[_selectedSibling];
                if (selectedSib.HasDataBlob <OrbitDB>())
                {
                    _targetSMA = (float)_siblingEntities[_selectedSibling].GetDataBlob <OrbitDB>().SemiMajorAxis;
                }
                if (selectedSib.HasDataBlob <OrbitUpdateOftenDB>())
                {
                    _targetSMA = (float)_siblingEntities[_selectedSibling].GetDataBlob <OrbitUpdateOftenDB>().SemiMajorAxis;
                }
                if (selectedSib.HasDataBlob <NewtonMoveDB>())
                {
                    _targetSMA = (float)_siblingEntities[_selectedSibling].GetDataBlob <NewtonMoveDB>().GetElements().SemiMajorAxis;
                }
            }

            //TODO this should be radius from orbiting body not major axies.
            ImGui.SliderFloat("Target SemiMajorAxis", ref _targetSMA, smaMin, smaMax);
            var manuvers = InterceptCalcs.Hohmann2(_sgp, mySMA, _targetSMA);



            double totalManuverDV = 0;

            foreach (var manuver in manuvers)
            {
                ImGui.Text(manuver.deltaV.Length() + "Δv");
                totalManuverDV += manuver.deltaV.Length();
            }

            if (totalManuverDV > _totalDV)
            {
                ImGui.TextColored(new Vector4(0.9f, 0, 0, 1), "Total Δv for all manuvers: " + Stringify.Velocity(totalManuverDV));
            }
            else
            {
                ImGui.Text("Total Δv for all manuvers: " + Stringify.Velocity(totalManuverDV));
            }

            if (ImGui.Button("Make it so"))
            {
                NewtonThrustCommand.CreateCommand(_orderEntity.FactionOwner, _orderEntity, _atDatetime, manuvers[0].deltaV);
                DateTime futureDate = _atDatetime + TimeSpan.FromSeconds(manuvers[1].timeInSeconds);
                NewtonThrustCommand.CreateCommand(_orderEntity.FactionOwner, _orderEntity, futureDate, manuvers[1].deltaV);
            }
        }
コード例 #4
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.
        }