示例#1
0
        internal static void FirstRun(Entity entity)
        {
            CargoTransferDB datablob = entity.GetDataBlob <CargoTransferDB>();

            double?dv;

            if (entity.HasDataBlob <OrbitDB>() && datablob.CargoToEntity.HasDataBlob <OrbitDB>())
            {
                dv = CalcDVDifferenceKmPerSecond(entity.GetDataBlob <OrbitDB>(), datablob.CargoToEntity.GetDataBlob <OrbitDB>());
            }
            else
            {
                OrbitDB orbitDB;
                if (entity.HasDataBlob <ColonyInfoDB>())
                {
                    orbitDB = entity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <OrbitDB>();
                }
                else//if (datablob.CargoToEntity.HasDataBlob<ColonyInfoDB>())
                {
                    orbitDB = datablob.CargoToEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <OrbitDB>();
                }
                dv = Distance.AuToKm(OrbitMath.MeanOrbitalVelocityInAU(orbitDB));
            }
            if (dv != null)
            {
                datablob.TransferRateInKG = CalcTransferRate((double)dv, datablob.CargoFromDB, datablob.CargoToDB);
            }
        }
示例#2
0
        internal static void FirstRun(Entity entity)
        {
            CargoTransferDB transferDB = entity.GetDataBlob <CargoTransferDB>();
            double          dv_mps     = CalcDVDifference_m(entity, transferDB.CargoToEntity);
            var             rate       = CalcTransferRate(dv_mps, transferDB.CargoFromDB, transferDB.CargoToDB);

            transferDB.TransferRateInKG = rate;
        }
示例#3
0
        public void ProcessEntity(Entity entity, int deltaSeconds)
        {
            CargoTransferDB datablob = entity.GetDataBlob <CargoTransferDB>();
            OrbitDB         orbitDB  = entity.GetDataBlob <OrbitDB>();



            if (datablob.DistanceBetweenEntitys <= 100)//todo: this is going to have to be based of mass or something, ie being further away from a colony on a planet is ok, but two ships should be close.
            {
                for (int i = 0; i < datablob.ItemsLeftToTransfer.Count; i++)
                {
                    var        item         = datablob.ItemsLeftToTransfer[i];
                    ICargoable cargoItem    = item.Item1;
                    long       amountToXfer = item.Item2;

                    Guid cargoTypeID     = cargoItem.CargoTypeID;
                    int  itemMassPerUnit = cargoItem.Mass;

                    if (!datablob.CargoToDB.StoredCargoTypes.ContainsKey(cargoTypeID))
                    {
                        datablob.CargoToDB.StoredCargoTypes.Add(cargoTypeID, new CargoTypeStore());
                    }

                    var toCargoTypeStore       = datablob.CargoToDB.StoredCargoTypes[cargoTypeID];   //reference to the cargoType store we're pushing to.
                    var toCargoItemAndAmount   = toCargoTypeStore.ItemsAndAmounts;                   //reference to dictionary holding the cargo we want to send too
                    var fromCargoTypeStore     = datablob.CargoFromDB.StoredCargoTypes[cargoTypeID]; //reference to the cargoType store we're pulling from.
                    var fromCargoItemAndAmount = fromCargoTypeStore.ItemsAndAmounts;                 //reference to dictionary we want to pull cargo from.

                    long totalweightToTransfer    = itemMassPerUnit * amountToXfer;
                    long weightToTransferThisTick = Math.Min(totalweightToTransfer, datablob.TransferRateInKG * deltaSeconds); //only the amount that can be transfered in this timeframe.

                    weightToTransferThisTick = Math.Min(weightToTransferThisTick, toCargoTypeStore.FreeCapacityKg);            //check cargo to has enough weight capacity

                    long numberXfered = weightToTransferThisTick / itemMassPerUnit;                                            //get the number of items from the mass transferable
                    numberXfered = Math.Min(numberXfered, fromCargoItemAndAmount[cargoItem.ID]);                               //check from has enough to send.

                    weightToTransferThisTick = numberXfered * itemMassPerUnit;

                    if (!toCargoItemAndAmount.ContainsKey(cargoItem.ID))
                    {
                        toCargoItemAndAmount.Add(cargoItem.ID, numberXfered);
                    }
                    else
                    {
                        toCargoItemAndAmount[cargoItem.ID] += numberXfered;
                    }

                    toCargoTypeStore.FreeCapacityKg -= weightToTransferThisTick;

                    fromCargoItemAndAmount[cargoItem.ID] -= numberXfered;
                    fromCargoTypeStore.FreeCapacityKg    += weightToTransferThisTick;
                    datablob.ItemsLeftToTransfer[i]       = new Tuple <ICargoable, long>(cargoItem, amountToXfer -= numberXfered);
                }
            }
        }
        /// <summary>
        /// Validates and actions the command.
        /// may eventualy need to return a responce instead of void.
        /// This creates a CargoTranferDB from the command, which does all the work.
        /// the command is to create and enqueue a CargoTransferDB.
        /// </summary>
        internal override void ActionCommand(Game game)
        {
            CargoTransferDB newTransferDB = new CargoTransferDB();

            newTransferDB.CargoToEntity   = EntityCommanding;
            newTransferDB.CargoToDB       = EntityCommanding.GetDataBlob <CargoStorageDB>();
            newTransferDB.CargoFromEntity = loadFromEntity;
            newTransferDB.CargoFromDB     = loadFromEntity.GetDataBlob <CargoStorageDB>();

            newTransferDB.TotalAmountToTransfer = TotalAmountToTransfer;
            newTransferDB.ItemToTranfer         = (ICargoable)game.StaticData.FindDataObjectUsingID(ItemToTransfer);
            EntityCommanding.Manager.SetDataBlob(EntityCommanding.ID, newTransferDB);
            IsRunning = true;
        }
示例#5
0
        public void ProcessEntity(Entity entity, int deltaSeconds)
        {
            CargoTransferDB datablob = entity.GetDataBlob <CargoTransferDB>();

            if (datablob.DistanceBetweenEntitys <= 100)//todo: this is going to have to be based of mass or something, ie being further away from a colony on a planet is ok, but two ships should be close.
            {
                Guid cargoTypeID     = datablob.ItemToTranfer.CargoTypeID;
                int  itemMassPerUnit = datablob.ItemToTranfer.Mass;
                if (!datablob.CargoToDB.StoredCargoTypes.ContainsKey(cargoTypeID))
                {
                    datablob.CargoToDB.StoredCargoTypes.Add(cargoTypeID, new CargoTypeStore());
                }

                var toCargoTypeStore       = datablob.CargoToDB.StoredCargoTypes[cargoTypeID];   //reference to the cargoType store we're pushing to.
                var toCargoItemAndAmount   = toCargoTypeStore.ItemsAndAmounts;                   //reference to dictionary holding the cargo we want to send too
                var fromCargoTypeStore     = datablob.CargoFromDB.StoredCargoTypes[cargoTypeID]; //reference to the cargoType store we're pulling from.
                var fromCargoItemAndAmount = fromCargoTypeStore.ItemsAndAmounts;                 //reference to dictionary we want to pull cargo from.

                datablob.TransferRate = 100;                                                     //todo set transfer rates on cargostorageDB and get either an average or a math.min. probibly an average.

                long totalweightToTransfer    = itemMassPerUnit * (datablob.AmountTransfered - datablob.TotalAmountToTransfer);
                long weightToTransferThisTick = Math.Min(totalweightToTransfer, datablob.TransferRate * deltaSeconds);   //only the amount that can be transfered in this timeframe.
                weightToTransferThisTick = Math.Min(weightToTransferThisTick, toCargoTypeStore.FreeCapacity);            //check cargo to has enough weight capacity

                long numberOfItems = weightToTransferThisTick / itemMassPerUnit;                                         //get the number of items from the mass transferable
                numberOfItems = Math.Min(numberOfItems, fromCargoItemAndAmount[datablob.ItemToTranfer.ID]);              //check from has enough to send.

                weightToTransferThisTick = numberOfItems * itemMassPerUnit;

                if (!toCargoItemAndAmount.ContainsKey(datablob.ItemToTranfer.ID))
                {
                    toCargoItemAndAmount.Add(datablob.ItemToTranfer.ID, numberOfItems);
                }
                else
                {
                    toCargoItemAndAmount[datablob.ItemToTranfer.ID] += numberOfItems;
                }

                toCargoTypeStore.FreeCapacity -= weightToTransferThisTick;

                fromCargoItemAndAmount[datablob.ItemToTranfer.ID] -= numberOfItems;
                fromCargoTypeStore.FreeCapacity += weightToTransferThisTick;
                datablob.AmountTransfered       += numberOfItems;
            }
        }
示例#6
0
        /// <summary>
        /// Validates and actions the command.
        /// may eventualy need to return a responce instead of void.
        /// This creates a CargoTranferDB from the command, which does all the work.
        /// the command is to create and enqueue a CargoTransferDB.
        /// </summary>
        internal override void ActionCommand(Game game)
        {
            if (!IsRunning)
            {
                _cargoTransferDB = new CargoTransferDB();
                _cargoTransferDB.CargoToEntity   = sendToEntity;
                _cargoTransferDB.CargoToDB       = sendToEntity.GetDataBlob <CargoStorageDB>();
                _cargoTransferDB.CargoFromEntity = EntityCommanding;
                _cargoTransferDB.CargoFromDB     = EntityCommanding.GetDataBlob <CargoStorageDB>();

                _cargoTransferDB.ItemsLeftToTransfer = ItemICargoablesToTransfer;
                _cargoTransferDB.OrderedToTransfer   = ItemICargoablesToTransfer;

                EntityCommanding.Manager.SetDataBlob(EntityCommanding.ID, _cargoTransferDB);
                CargoTransferProcessor.FirstRun(EntityCommanding);
                IsRunning = true;
            }
        }
示例#7
0
        public void ProcessEntity(Entity entity, int deltaSeconds)
        {
            CargoTransferDB transferDB = entity.GetDataBlob <CargoTransferDB>();

            for (int i = 0; i < transferDB.ItemsLeftToTransfer.Count; i++)
            {
                (ICargoable item, long amount)itemsToXfer = transferDB.ItemsLeftToTransfer[i];
                ICargoable cargoItem    = itemsToXfer.item;
                long       amountToXfer = itemsToXfer.amount;

                Guid   cargoTypeID     = cargoItem.CargoTypeID;
                double itemMassPerUnit = cargoItem.MassPerUnit;

                if (!transferDB.CargoToDB.TypeStores.ContainsKey(cargoTypeID))
                {
                    string errmsg = "This entity cannot store this type of cargo";
                    StaticRefLib.EventLog.AddGameEntityErrorEvent(entity, errmsg);
                }

                var toCargoTypeStore       = transferDB.CargoToDB.TypeStores[cargoTypeID];   //reference to the cargoType store we're pushing to.
                var toCargoItemAndAmount   = toCargoTypeStore.CurrentStoreInUnits;           //reference to dictionary holding the cargo we want to send too
                var fromCargoTypeStore     = transferDB.CargoFromDB.TypeStores[cargoTypeID]; //reference to the cargoType store we're pulling from.
                var fromCargoItemAndAmount = fromCargoTypeStore.CurrentStoreInUnits;         //reference to dictionary we want to pull cargo from.

                //the transfer speed is mass based, not unit based.
                double totalMassToTransfer    = itemMassPerUnit * amountToXfer;
                double massToTransferThisTick = Math.Min(totalMassToTransfer, transferDB.TransferRateInKG * deltaSeconds); //only the amount that can be transfered in this timeframe.

                //TODO: this wont handle objects that have a larger unit mass than the availible transferRate,
                //but maybe that makes for a game mechanic
                int countToTransferThisTick = (int)(massToTransferThisTick / itemMassPerUnit);

                var amountFrom = transferDB.CargoFromDB.RemoveCargoByUnit(cargoItem, countToTransferThisTick);
                var amountTo   = transferDB.CargoToDB.AddCargoByUnit(cargoItem, countToTransferThisTick);

                if (amountTo != amountFrom)
                {
                    throw new Exception("something went wrong here");
                }
                var newAmount = transferDB.ItemsLeftToTransfer[i].amount - amountTo;
                transferDB.ItemsLeftToTransfer[i] = (cargoItem, newAmount);
            }
        }