public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (var componentDesign in componentInstances.SpecificInstances)
            {
                var componentVolume  = componentDesign.Key.GetDataBlob <MassVolumeDB>().Volume;
                var componentTonnage = componentDesign.Key.GetDataBlob <ComponentInfoDB>().SizeInTons;

                foreach (var componentInstance in componentDesign.Value)
                {
                    totalHTK     += componentInstance.GetDataBlob <ComponentInstanceInfoDB>().HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                    if (!componentInstances.ComponentDictionary.ContainsKey(componentInstance))
                    {
                        componentInstances.ComponentDictionary.Add(componentInstance, totalVolume);
                    }
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                ShipMovementProcessor.CalcMaxSpeed(shipEntity);
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.Volume = totalVolume;
        }
 internal override void ActionCommand(Game game)
 {
     OrderableProcessor.ProcessOrderList(game, NestedCommands);
     if (NestedCommands.Count == 0)
     {
         if (!IsRunning)
         {
             var    entPos     = _entityCommanding.GetDataBlob <PositionDB>().PositionInKm;
             var    tarPos     = _targetEntity.GetDataBlob <PositionDB>().PositionInKm;
             double distanceAU = PositionDB.GetDistanceBetween(_entityCommanding.GetDataBlob <PositionDB>(), _targetEntity.GetDataBlob <PositionDB>());
             var    rangeAU    = ApihelionInKM / GameConstants.Units.KmPerAu;
             if (Math.Abs(rangeAU - distanceAU) <= 500 / GameConstants.Units.MetersPerAu) //distance within 500m
             {
                 DateTime datenow  = _entityCommanding.Manager.ManagerSubpulses.SystemLocalDateTime;
                 var      newOrbit = ShipMovementProcessor.CreateOrbitHereWithPerihelion(_entityCommanding, _targetEntity, PerhelionInKM, datenow);
                 _entityCommanding.SetDataBlob(newOrbit);
                 IsRunning = true;
             }
             else //insert new translate move
             {
                 var cmd = new TranslateMoveCommand()
                 {
                     RequestingFactionGuid = this.RequestingFactionGuid, EntityCommandingGuid = this.EntityCommandingGuid, CreatedDate = this.CreatedDate, TargetEntityGuid = this.TargetEntityGuid, RangeInKM = this.ApihelionInKM
                 };
                 NestedCommands.Insert(0, cmd);
                 cmd.IsValidCommand(game);
                 cmd.ActionCommand(game);
             }
         }
     }
 }
Example #3
0
        public static void StartNonNewtTranslation(Entity entity)
        {
            var moveDB       = entity.GetDataBlob <TranslateMoveDB>();
            var propulsionDB = entity.GetDataBlob <PropulsionAbilityDB>();
            var positionDB   = entity.GetDataBlob <PositionDB>();
            var maxSpeedMS   = propulsionDB.MaximumSpeed_MS;

            positionDB.SetParent(null);
            Vector3 targetPosMt       = Distance.AuToMt(moveDB.TranslateExitPoint_AU);
            Vector3 currentPositionMt = Distance.AuToMt(positionDB.AbsolutePosition_AU);

            Vector3 postionDelta  = currentPositionMt - targetPosMt;
            double  totalDistance = postionDelta.Length();

            double maxKMeters        = ShipMovementProcessor.CalcMaxFuelDistance_KM(entity);
            double fuelMaxDistanceMt = maxKMeters * 1000;

            if (fuelMaxDistanceMt >= totalDistance)
            {
                var currentVelocityMS = Vector3.Normalise(targetPosMt - currentPositionMt) * maxSpeedMS;
                propulsionDB.CurrentVectorMS       = currentVelocityMS;
                moveDB.CurrentNonNewtonionVectorMS = currentVelocityMS;
                moveDB.LastProcessDateTime         = entity.Manager.ManagerSubpulses.StarSysDateTime;

                CargoStorageDB storedResources = entity.GetDataBlob <CargoStorageDB>();
                foreach (var item in propulsionDB.FuelUsePerKM)
                {
                    var fuel = staticData.GetICargoable(item.Key);
                    StorageSpaceProcessor.RemoveCargo(storedResources, fuel, (long)(item.Value * totalDistance / 1000));
                }
            }
        }
Example #4
0
 public void OnComponentInstalation(Entity parentEntity, Entity componentInstance)
 {
     if (!parentEntity.HasDataBlob <PropulsionAbilityDB>())
     {
         parentEntity.SetDataBlob(new PropulsionAbilityDB());
     }
     ShipMovementProcessor.CalcMaxSpeedAndFuelUsage(parentEntity);
 }
Example #5
0
        public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Entity parent, StarSystem starsys, string shipName = null)
        {
            Vector3 position           = parent.GetDataBlob <PositionDB>().AbsolutePosition_AU;
            var     distanceFromParent = parent.GetDataBlob <MassVolumeDB>().Radius * 2;

            position.X += distanceFromParent;
            Entity ship = CreateShip(classEntity, systemEntityManager, ownerFaction, position, starsys, shipName);

            ship.GetDataBlob <PositionDB>().SetParent(parent);
            var orbitDB = ShipMovementProcessor.CreateOrbitHereWithSemiMajAxis(ship, parent, Distance.AuToKm(distanceFromParent), systemEntityManager.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(orbitDB);

            return(ship);
        }
Example #6
0
        internal void ProcessSystem(DateTime toDateTime)
        {
            //check validity of commands etc. here.


            //the system may need to run several times for a wanted tickLength
            //keep processing the system till we've reached the wanted ticklength
            while (SystemLocalDateTime < toDateTime)
            {
                //calculate max time the system can run/time to next interupt
                //this should handle predicted events, ie econ, production, shipjumps, sensors etc.
                TimeSpan timeDeltaMax = toDateTime - SystemLocalDateTime;
                DateTime nextDate     = GetNextInterupt(timeDeltaMax);
                TimeSpan deltaActual  = nextDate - SystemLocalDateTime;

                ShipMovementProcessor.Process(_entityManager, (int)deltaActual.TotalSeconds); //process movement for any entity that can move (not orbit)

                ProcessToNextInterupt(nextDate);
            }
        }
Example #7
0
 public void OnComponentInstallation(Entity parentEntity, ComponentInstance componentInstance)
 {
     if (!parentEntity.HasDataBlob <WarpAbilityDB>())
     {
         var ablty = new WarpAbilityDB();
         ablty.EnergyType         = EnergyType;
         ablty.BubbleCreationCost = BubbleCreationCost;
         ablty.BubbleSustainCost  = BubbleSustainCost;
         ablty.BubbleCollapseCost = BubbleCollapseCost;
         parentEntity.SetDataBlob(ablty);
     }
     else
     {
         var ablty = parentEntity.GetDataBlob <WarpAbilityDB>();
         ablty.BubbleCreationCost += BubbleCreationCost;
         ablty.BubbleSustainCost  += BubbleSustainCost;
         ablty.BubbleCollapseCost += BubbleCollapseCost;
     }
     ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(parentEntity);
 }
        public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (KeyValuePair <Guid, List <ComponentInstance> > instance in componentInstances.GetComponentsByDesigns())
            {
                var componentVolume  = componentInstances.AllDesigns[instance.Key].VolumePerUnit;
                var componentTonnage = componentInstances.AllDesigns[instance.Key].MassPerUnit;

                foreach (var componentInstance in instance.Value)
                {
                    totalHTK     += componentInstance.HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                if (shipEntity.HasDataBlob <WarpAbilityDB>())
                {
                    ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(shipEntity);
                }
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.MassDry     = totalTonnage;
            mvDB.Volume_m3   = totalVolume;
            mvDB.Density_gcm = MassVolumeDB.CalculateDensity(totalTonnage, totalVolume);
            mvDB.RadiusInAU  = MassVolumeDB.CalculateRadius_Au(totalTonnage, mvDB.Density_gcm);
        }
Example #9
0
 /// <summary>
 /// Prepares, and defines the order that processors are run in.
 /// </summary>
 private static void InitializeProcessors()
 {
     ShipMovementProcessor.Initialize();
     //InstallationProcessor.Initialize();
 }
        public void ProcessEntity(Entity entity, int deltaSeconds)
        {
            var manager      = entity.Manager;
            var moveDB       = entity.GetDataBlob <TranslateMoveDB>();
            var propulsionDB = entity.GetDataBlob <PropulsionDB>();
            //var currentVector = propulsionDB.CurrentSpeed;
            var maxSpeed        = propulsionDB.MaximumSpeed;
            var positionDB      = entity.GetDataBlob <PositionDB>();
            var currentPosition = positionDB.AbsolutePosition;
            //targetPosition taking the range (how close we want to get) into account.
            var targetPos = moveDB.TargetPosition * (1 - (moveDB.MoveRangeInKM / GameConstants.Units.KmPerAu) / moveDB.TargetPosition.Length());

            var deltaVecToTarget = currentPosition - targetPos;


            var currentSpeed = GMath.GetVector(currentPosition, targetPos, maxSpeed);

            propulsionDB.CurrentVector = currentSpeed;
            moveDB.CurrentVector       = currentSpeed;
            StaticDataStore           staticData      = entity.Manager.Game.StaticData;
            CargoStorageDB            storedResources = entity.GetDataBlob <CargoStorageDB>();
            Dictionary <Guid, double> fuelUsePerMeter = propulsionDB.FuelUsePerKM;
            double maxKMeters = ShipMovementProcessor.CalcMaxFuelDistance(entity);

            var nextTPos = currentPosition + (currentSpeed * deltaSeconds);


            var distanceToTargetAU = deltaVecToTarget.Length();  //in au

            var deltaVecToNextT   = currentPosition - nextTPos;
            var fuelMaxDistanceAU = maxKMeters / GameConstants.Units.KmPerAu;



            Vector4 newPos = currentPosition;

            double distanceToNextTPos = deltaVecToNextT.Length();
            double distanceToMove;

            if (fuelMaxDistanceAU < distanceToNextTPos)
            {
                distanceToMove = fuelMaxDistanceAU;
                double percent = fuelMaxDistanceAU / distanceToNextTPos;
                newPos = nextTPos + deltaVecToNextT * percent;
                Event usedAllFuel = new Event(manager.ManagerSubpulses.SystemLocalDateTime, "Used all Fuel", entity.GetDataBlob <OwnedDB>().OwnedByFaction, entity);
                usedAllFuel.EventType = EventType.FuelExhausted;
                manager.Game.EventLog.AddEvent(usedAllFuel);
            }
            else
            {
                distanceToMove = distanceToNextTPos;
                newPos         = nextTPos;
            }



            if (distanceToTargetAU < distanceToMove) // moving would overtake target, just go directly to target
            {
                distanceToMove             = distanceToTargetAU;
                propulsionDB.CurrentVector = new Vector4(0, 0, 0, 0);
                newPos            = targetPos;
                moveDB.IsAtTarget = true;
                entity.RemoveDataBlob <TranslateMoveDB>();
            }

            positionDB.AbsolutePosition = newPos;
            int kMetersMoved = (int)(distanceToMove * GameConstants.Units.KmPerAu);

            foreach (var item in propulsionDB.FuelUsePerKM)
            {
                var fuel = staticData.GetICargoable(item.Key);
                StorageSpaceProcessor.RemoveCargo(storedResources, fuel, (long)(item.Value * kMetersMoved));
            }
        }
 public void ProcessManager(EntityManager manager, int deltaSeconds)
 {
     ShipMovementProcessor.Process(manager, deltaSeconds);
 }
Example #12
0
        public void SMSetOrbitToEntity(Entity entity, Entity parentEntity, double perihelionKM, DateTime time)
        {
            var db = ShipMovementProcessor.CreateOrbitHereWithPerihelion(entity, parentEntity, perihelionKM, time);

            entity.SetDataBlob(db);
        }