Ejemplo n.º 1
0
 public PropulsionAbilityDB(PropulsionAbilityDB propulsionDB)
 {
     MaximumSpeed_MS  = propulsionDB.MaximumSpeed_MS;
     CurrentVectorMS  = propulsionDB.CurrentVectorMS;
     TotalEnginePower = propulsionDB.TotalEnginePower;
     FuelUsePerKM     = new Dictionary <Guid, double>(propulsionDB.FuelUsePerKM);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This intercept only works if time to intercept is less than the orbital period.
        /// </summary>
        /// <returns>The ntercept.</returns>
        /// <param name="mover">Mover.</param>
        /// <param name="targetOrbit">Target orbit.</param>
        /// <param name="atDateTime">At date time.</param>
        public static (Vector3, TimeSpan) FTLIntercept(Entity mover, OrbitDB targetOrbit, DateTime atDateTime)
        {
            //OrbitDB targetOrbit = target.GetDataBlob<OrbitDB>();
            //PositionDB targetPosition = target.GetDataBlob<PositionDB>();
            //PositionDB moverPosition = mover.GetDataBlob<PositionDB>();

            OrbitDB moverOrbit   = mover.GetDataBlob <OrbitDB>();
            Vector3 moverPosInKM = Distance.AuToKm(OrbitProcessor.GetAbsolutePosition_AU(moverOrbit, atDateTime));

            PropulsionAbilityDB moverPropulsion = mover.GetDataBlob <PropulsionAbilityDB>();

            Vector3 targetPosInKM = Distance.AuToKm((OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, atDateTime)));

            int speed = 25000;//moverPropulsion.MaximumSpeed * 100; //299792458;

            (Vector3, TimeSpan)intercept = (new Vector3(), TimeSpan.Zero);



            TimeSpan eti      = new TimeSpan();
            TimeSpan eti_prev = new TimeSpan();
            DateTime edi      = atDateTime;
            DateTime edi_prev = atDateTime;

            Vector3 predictedPosKM = Distance.AuToKm(OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, edi_prev));
            double  distance       = (predictedPosKM - moverPosInKM).Length();

            eti = TimeSpan.FromSeconds((distance * 1000) / speed);

            int steps = 0;

            if (eti < targetOrbit.OrbitalPeriod)
            {
                double timeDifference     = double.MaxValue;
                double distanceDifference = timeDifference * speed;
                while (distanceDifference >= 1000)
                {
                    eti_prev = eti;
                    edi_prev = edi;

                    predictedPosKM = Distance.AuToKm(OrbitProcessor.GetAbsolutePosition_AU(targetOrbit, edi_prev));

                    distance = (predictedPosKM - moverPosInKM).Length();
                    eti      = TimeSpan.FromSeconds((distance * 1000) / speed);
                    edi      = atDateTime + eti;

                    timeDifference     = Math.Abs(eti.TotalSeconds - eti_prev.TotalSeconds);
                    distanceDifference = timeDifference * speed;
                    steps++;
                }
            }

            return(intercept);
        }
Ejemplo n.º 3
0
        public TranslationMoveVM(Game game, CommandReferences cmdRef, Entity entity)
        {
            _tMoveDB = entity.GetDataBlob <TranslateMoveDB>();
            _posDB   = entity.GetDataBlob <PositionDB>();
            _propDB  = entity.GetDataBlob <PropulsionAbilityDB>();
            _cmdRef  = cmdRef;
            TargetList.SelectionChangedEvent += OnTargetSelectonChange;
            Entity faction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);
            UpdateTargetList(faction, entity.Manager);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// recalculates a shipsMaxSpeed.
        /// </summary>
        /// <param name="ship"></param>
        public static void CalcMaxSpeedAndFuelUsage(Entity ship)
        {
            int totalEnginePower = 0;
            Dictionary <Guid, double> totalFuelUsage = new Dictionary <Guid, double>();
            var instancesDB = ship.GetDataBlob <ComponentInstancesDB>();
            var designs     = instancesDB.GetDesignsByType(typeof(EnginePowerAtbDB));

            foreach (var design in designs)
            {
                foreach (var instanceInfo in instancesDB.GetComponentsBySpecificDesign(design.Guid))
                {
                    var power     = instanceInfo.DesignEntity.GetDataBlob <EnginePowerAtbDB>();
                    var fuelUsage = instanceInfo.DesignEntity.GetDataBlob <ResourceConsumptionAtbDB>();
                    if (instanceInfo.IsEnabled)
                    {
                        totalEnginePower += (int)(power.EnginePower * instanceInfo.HealthPercent());
                        foreach (var item in fuelUsage.MaxUsage)
                        {
                            totalFuelUsage.SafeValueAdd(item.Key, item.Value);
                        }
                    }
                }
            }



            /*
             * List<KeyValuePair<Entity,PrIwObsList<Entity>>> engineEntities = instancesDB.SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob<EnginePowerAtbDB>()).ToList();
             * foreach (var engineDesign in engineEntities)
             * {
             *  foreach (var engineInstance in engineDesign.Value)
             *  {
             *      //todo check if it's damaged
             *      totalEnginePower += engineDesign.Key.GetDataBlob<EnginePowerAtbDB>().EnginePower;
             *      foreach (var kvp in engineDesign.Key.GetDataBlob<ResourceConsumptionAtbDB>().MaxUsage)
             *      {
             *          totalFuelUsage.SafeValueAdd(kvp.Key, kvp.Value);
             *      }
             *  }
             * }*/

            //Note: TN aurora uses the TCS for max speed calcs.
            PropulsionAbilityDB propulsionDB = ship.GetDataBlob <PropulsionAbilityDB>();

            propulsionDB.TotalEnginePower = totalEnginePower;
            propulsionDB.FuelUsePerKM     = totalFuelUsage;
            var mass     = ship.GetDataBlob <ShipInfoDB>().Tonnage;
            var maxSpeed = MaxSpeedCalc(totalEnginePower, mass);

            propulsionDB.MaximumSpeed_MS = maxSpeed;
        }
Ejemplo n.º 5
0
        void SetOrbitHere(Entity entity, PropulsionAbilityDB propulsionDB, PositionDB positionDB, TranslateMoveDB moveDB, DateTime atDateTime)
        {
            propulsionDB.CurrentVectorMS = new Vector3(0, 0, 0);

            double targetSOI = OrbitProcessor.GetSOI(moveDB.TargetEntity);

            Entity targetEntity;

            if (moveDB.TargetEntity.GetDataBlob <PositionDB>().GetDistanceTo(positionDB) > targetSOI)
            {
                targetEntity = moveDB.TargetEntity.GetDataBlob <OrbitDB>().Parent; //TODO: it's concevable we could be in another SOI not the parent (ie we could be in a target's moon's SOI)
            }
            else
            {
                targetEntity = moveDB.TargetEntity;
            }
            OrbitDB targetOrbit         = targetEntity.GetDataBlob <OrbitDB>();
            var     orbitalVector       = OrbitProcessor.GetOrbitalVector(targetOrbit, atDateTime);
            var     insertionVector2d   = OrbitProcessor.GetOrbitalInsertionVector(moveDB.SavedNewtonionVector_AU, targetOrbit, atDateTime);
            Vector3 parentOrbitalVector = new Vector3(orbitalVector.X, orbitalVector.Y, 0);
            Vector3 insertionVector     = new Vector3(insertionVector2d.X, insertionVector2d.Y, 0);

            insertionVector             += moveDB.ExpendDeltaV_AU; //TODO: only use it if we have it.
            propulsionDB.RemainingDV_MS -= (float)Distance.AuToMt(moveDB.ExpendDeltaV_AU).Length();
            OrbitDB newOrbit = OrbitDB.FromVector(targetEntity, entity, insertionVector, atDateTime);

            if (newOrbit.Periapsis > targetSOI)
            {
                //TODO: find who's SOI we're currently in and create an orbit for that;
            }
            if (newOrbit.Apoapsis > targetSOI)
            {
                //TODO: change orbit to new parent at SOI change
            }

            positionDB.SetParent(targetEntity);
            moveDB.IsAtTarget = true;
            entity.RemoveDataBlob <TranslateMoveDB>();
            entity.SetDataBlob(newOrbit);
            newOrbit.SetParent(targetEntity);
        }
Ejemplo n.º 6
0
        public static double CalcMaxFuelDistance_KM(Entity shipEntity)
        {
            CargoStorageDB      storedResources = shipEntity.GetDataBlob <CargoStorageDB>();
            PropulsionAbilityDB propulsionDB    = shipEntity.GetDataBlob <PropulsionAbilityDB>();
            StaticDataStore     staticData      = shipEntity.Manager.Game.StaticData;
            ICargoable          fuelResource;
            double distance = 0;

            foreach (var fuelAndUsage in propulsionDB.FuelUsePerKM)
            {
                fuelResource = staticData.GetICargoable(fuelAndUsage.Key);
                var usePerKm = fuelAndUsage.Value;
                if (storedResources.StoredCargoTypes.ContainsKey(fuelResource.CargoTypeID))
                {
                    if (storedResources.StoredCargoTypes[fuelResource.CargoTypeID].ItemsAndAmounts.ContainsKey(fuelResource.ID))
                    {
                        long fuelStored = storedResources.StoredCargoTypes[fuelResource.CargoTypeID].ItemsAndAmounts[fuelResource.ID];
                        distance += fuelStored / fuelAndUsage.Value;
                    }
                }
            }
            return(distance);
        }