Пример #1
0
        /// <summary>
        /// Currently this only calculates the change in velocity from 0 to planet radius +* 0.33333.
        /// TODO: add gravity drag and atmosphere drag, and tech improvements for such.
        /// </summary>
        /// <param name="planetEntity"></param>
        /// <param name="payload"></param>
        /// <returns></returns>
        public static double FuelCostToLowOrbit(Entity planetEntity, double payload)
        {
            var lowOrbit = LowOrbitRadius(planetEntity);

            var     exaustVelocity = 275;
            var     sgp            = OrbitMath.CalculateStandardGravityParameter(payload, planetEntity.GetDataBlob <MassVolumeDB>().Mass);
            Vector3 pos            = new Vector3(lowOrbit, 0, 0);

            var vel      = OrbitMath.ObjectLocalVelocityPolar(sgp, pos, lowOrbit, 0, 0, 0);
            var fuelCost = OrbitMath.TsiolkovskyFuelCost(payload, exaustVelocity, vel.speed);

            return(fuelCost);
        }
Пример #2
0
        internal override void ActionCommand(DateTime atDateTime)
        {
            if (atDateTime < ActionOnDate)
            {
                return;
            }
            if (!IsRunning)
            {
                IsRunning        = true;
                _newtonAbilityDB = _entityCommanding.GetDataBlob <NewtonThrustAbilityDB>();
                _startDV         = _newtonAbilityDB.DeltaV;
                _fuelBurnRate    = _newtonAbilityDB.FuelBurnRate;
                _totalFuel       = _newtonAbilityDB.TotalFuel_kg;
                var soiParentEntity = Entity.GetSOIParentEntity(_entityCommanding);
                _soiParentMass = soiParentEntity.GetDataBlob <MassVolumeDB>().MassDry;
                var currentVel = Entity.GetRalitiveFutureVelocity(_entityCommanding, atDateTime);
                if (_entityCommanding.HasDataBlob <OrbitDB>())
                {
                    _entityCommanding.RemoveDataBlob <OrbitDB>();
                }
                if (_entityCommanding.HasDataBlob <OrbitUpdateOftenDB>())
                {
                    _entityCommanding.RemoveDataBlob <OrbitUpdateOftenDB>();
                }
                if (_entityCommanding.HasDataBlob <NewtonMoveDB>())
                {
                    _newtonMovedb = _entityCommanding.GetDataBlob <NewtonMoveDB>();
                }
                else
                {
                    _newtonMovedb = new NewtonMoveDB(soiParentEntity, currentVel);
                }

                _entityCommanding.SetDataBlob(_newtonMovedb);
            }
            var halfDV  = _startDV * 0.5; //lets burn half the dv getting into a good intercept.
            var dvUsed  = _startDV - _newtonAbilityDB.DeltaV;
            var dvToUse = halfDV - dvUsed;

            if (dvToUse > 0)
            {
                (Vector3 Position, Vector3 Velocity)curOurRalState = Entity.GetRalitiveState(_entityCommanding);
                (Vector3 Position, Vector3 Velocity)curTgtRalState = Entity.GetRalitiveState(_targetEntity);
                var dvRemaining = _newtonAbilityDB.DeltaV;

                var tgtVelocity = Entity.GetAbsoluteFutureVelocity(_targetEntity, atDateTime);
                //calculate the differencecs in velocity vectors.
                Vector3 leadToTgt = (curTgtRalState.Velocity - curOurRalState.Velocity);

                //convert the lead to an orbit ralitive (prograde Y) vector.
                //var manuverVector = OrbitMath.GlobalToOrbitVector(leadToTgt, curOurRalState.Position, curOurRalState.Velocity);


                var burnRate = _newtonAbilityDB.FuelBurnRate;
                //var foo = OrbitMath.TsiolkovskyFuelUse(_totalFuel, )
                var fuelUse = OrbitMath.TsiolkovskyFuelCost(
                    _newtonAbilityDB.TotalFuel_kg,
                    _newtonAbilityDB.ExhaustVelocity,
                    dvToUse//pretty sure this should be dvToUse, but that's giving me a silent crash.
                    );
                var burnTime = fuelUse / burnRate;

                var manuverVector = ManuverVector(dvToUse, burnTime, curOurRalState, curTgtRalState, atDateTime);

                _newtonMovedb.DeltaVForManuver_FoRO_m = manuverVector;
                _entityCommanding.Manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(5), nameof(OrderableProcessor), _entityCommanding);
            }
            else
            {
                _newtonMovedb.DeltaVForManuver_FoRO_m = new Vector3();
            }
        }