示例#1
0
        /// <summary>
        /// Add or removes cargo from storage, ignores transfer rate.
        /// </summary>
        /// <param name="cargoItem"></param>
        /// <param name="mass">negitive to remove</param>
        /// <returns>amount succesfully added or removed</returns>
        internal double AddRemoveCargoByMass(ICargoable cargoItem, double mass)
        {
            //check we're actualy capable of

            if (!TypeStores.ContainsKey(cargoItem.CargoTypeID))
            {
                var    type      = StaticRefLib.StaticData.CargoTypes[cargoItem.CargoTypeID];
                string errString = "Can't add or remove " + cargoItem.Name + " because this entity cannot even store " + type.Name + " types of cargo";
                StaticRefLib.EventLog.AddPlayerEntityErrorEvent(OwningEntity, errString);
                return(0);
            }
            TypeStore store = TypeStores[cargoItem.CargoTypeID];


            double unitsToTryStore = cargoItem.MassPerUnit * mass;
            double unitsStorable   = store.FreeVolume / cargoItem.VolumePerUnit;

            int    unitsStoring  = (int)Math.Min(unitsToTryStore, unitsStorable);
            double volumeStoring = unitsStoring * cargoItem.VolumePerUnit;
            double massStoring   = unitsStoring * cargoItem.MassPerUnit;

            if (!store.CurrentStoreInUnits.ContainsKey(cargoItem.ID))
            {
                store.CurrentStoreInUnits.Add(cargoItem.ID, unitsStoring);
                store.Cargoables.Add(cargoItem.ID, cargoItem);
            }
            else
            {
                store.CurrentStoreInUnits[cargoItem.ID] += unitsStoring;
            }

            store.FreeVolume -= volumeStoring;
            TotalStoredMass  += massStoring;

            return(massStoring);
        }
示例#2
0
 public CargoItemVM(ICargoable cargoableItem)
 {
     CargoableItem = cargoableItem;
 }
示例#3
0
        /// <summary>
        /// Checks storage capacity and transferes either the amount or the amount that toCargo is capable of storing.
        /// </summary>
        /// <param name="fromCargo"></param>
        /// <param name="toCargo"></param>
        /// <param name="item"></param>
        /// <param name="amount"></param>
        internal static void TransferCargo(CargoStorageDB fromCargo, CargoStorageDB toCargo, ICargoable item, int amount)
        {
            Guid  cargoTypeID = item.CargoTypeID;
            float itemWeight  = item.Mass;
            Guid  itemID      = item.ID;

            long  remainingWeightCapacity = RemainingCapacity(toCargo, cargoTypeID);
            long  remainingNumCapacity    = (long)(remainingWeightCapacity / itemWeight);
            float amountWeight            = amount * itemWeight;

            if (remainingNumCapacity >= amount)
            {
                //AddToCargo(toCargo, item, amount);
                //fromCargo.MinsAndMatsByCargoType[cargoTypeID][itemID] -= amount;
                long amountRemoved = SubtractValue(fromCargo, itemID, amount);
                AddValue(toCargo, item, amountRemoved);
            }
            else
            {
                //AddToCargo(toCargo, item, remainingNumCapacity);
                //fromCargo.MinsAndMatsByCargoType[cargoTypeID][itemID] -= remainingNumCapacity;
                long amountRemoved = SubtractValue(fromCargo, itemID, remainingNumCapacity);
                AddValue(toCargo, item, amountRemoved);
            }
        }
示例#4
0
        /// <summary>
        /// TODO: refineing rates should also limit the amount that can be refined for a specific mat each tick.
        /// </summary>
        internal static void RefineMaterials(Entity colony, Dictionary <Guid, ProcessedMaterialSD> processedMaterials)
        {
            CargoStorageDB  stockpiles     = colony.GetDataBlob <CargoStorageDB>();
            RefiningDB      refiningDB     = colony.GetDataBlob <RefiningDB>();
            StaticDataStore staticData     = colony.Manager.Game.StaticData;
            int             RefineryPoints = refiningDB.PointsPerTick;

            for (int jobIndex = 0; jobIndex < refiningDB.JobBatchList.Count; jobIndex++)
            {
                if (RefineryPoints > 0)
                {
                    var job = refiningDB.JobBatchList[jobIndex];
                    ProcessedMaterialSD material = processedMaterials[job.ItemGuid];
                    var costs = new Dictionary <Guid, int>(material.RawMineralCosts);
                    if (material.RefinedMateraialsCosts != null)
                    {
                        costs.Concat(new Dictionary <Guid, int>(material.RefinedMateraialsCosts));
                    }

                    Dictionary <ICargoable, int> cargoablecosts = new Dictionary <ICargoable, int>();
                    foreach (var kvp in material.RawMineralCosts)
                    {
                        ICargoable cargoItem = staticData.CargoGoods.GetMineral(kvp.Key);
                        cargoablecosts.Add(cargoItem, kvp.Value);
                    }

                    while (job.NumberCompleted < job.NumberOrdered && job.ProductionPointsLeft > 0)
                    {
                        if (job.ProductionPointsLeft == material.RefineryPointCost)
                        {
                            //consume all ingredients for this job on the first point use.
                            if (StorageSpaceProcessor.HasRequiredItems(stockpiles, cargoablecosts))
                            {
                                StorageSpaceProcessor.RemoveResources(stockpiles, cargoablecosts);
                            }
                            else
                            {
                                break;
                            }
                        }

                        //use Refinery points
                        ushort pointsUsed = (ushort)Math.Min(job.ProductionPointsLeft, material.RefineryPointCost);
                        job.ProductionPointsLeft -= pointsUsed;
                        RefineryPoints           -= pointsUsed;

                        //if job is complete
                        if (job.ProductionPointsLeft == 0)
                        {
                            job.NumberCompleted++;                                                       //complete job,
                            StorageSpaceProcessor.AddCargo(stockpiles, material, material.OutputAmount); //and add the product to the stockpile
                            job.ProductionPointsLeft = material.RefineryPointCost;                       //and reset the points left for the next job in the batch.
                        }
                    }
                    //if the whole batch is completed
                    if (job.NumberCompleted == job.NumberOrdered)
                    {
                        //remove it from the list
                        refiningDB.JobBatchList.RemoveAt(jobIndex);
                        if (job.Auto) //but if it's set to auto, re-add it.
                        {
                            job.ProductionPointsLeft = material.RefineryPointCost;
                            job.NumberCompleted      = 0;
                            refiningDB.JobBatchList.Add(job);
                        }
                    }
                }
            }
        }
示例#5
0
 public int GetFreeUnitSpace(ICargoable cargoItem)
 {
     return((int)(FreeVolume / cargoItem.VolumePerUnit));
 }
示例#6
0
 /// <summary>
 /// Returns the amount of free mass for a given cargoItem
 /// (mass = density * volume)
 /// </summary>
 /// <param name="cargoItem"></param>
 /// <returns></returns>
 public double GetFreeMass(ICargoable cargoItem)
 {
     return((FreeVolume / cargoItem.VolumePerUnit) * cargoItem.MassPerUnit);
 }
示例#7
0
 internal CargoItemVM(ICargoable cargoableItem)
 {
     _cargoableItem = cargoableItem;
 }
示例#8
0
 public static long GetAmount(CargoStorageDB storeDB, ICargoable item)
 {
     return(storeDB.StoredCargoTypes[item.CargoTypeID].ItemsAndAmounts[item.ID]);
 }
示例#9
0
        public void Display()
        {
            ImGui.BeginChild(_entityState.Name, new System.Numerics.Vector2(260, 200), true);
            ImGui.Text(_entityState.Name);
            ImGui.Text("Transfer Rate: " + _volStorageDB.TransferRateInKgHr);
            ImGui.Text("At DeltaV < " + Stringify.Velocity(_volStorageDB.TransferRangeDv_mps));

            foreach (var typeStore in _stores)
            {
                CargoTypeSD stype        = _staticData.CargoTypes[typeStore.Key];
                var         freeVolume   = typeStore.Value.FreeVolume;
                var         maxVolume    = typeStore.Value.MaxVolume;
                var         storedVolume = maxVolume - freeVolume;

                string headerText = stype.Name + " " + Stringify.Volume(freeVolume) + " / " + Stringify.Volume(maxVolume) + " free";
                ImGui.PushID(_entityState.Entity.Guid.ToString());
                if (ImGui.CollapsingHeader(headerText, ImGuiTreeNodeFlags.CollapsingHeader))
                {
                    ImGui.Columns(3);
                    ImGui.Text("Item");
                    ImGui.NextColumn();
                    ImGui.Text("Count");
                    ImGui.NextColumn();
                    ImGui.Text("Total Mass");
                    ImGui.NextColumn();
                    ImGui.Separator();

                    foreach (var cargoItemKvp in typeStore.Value.CurrentStoreInUnits.ToArray())
                    {
                        ICargoable cargoItem = _stores[typeStore.Key].Cargoables[cargoItemKvp.Key];
                        if (cargoItem == null)
                        {
                            FactionInfoDB factionInfoDB;
                            //factionInfoDB.
                        }

                        var cname         = cargoItem.Name;
                        var unitsStored   = cargoItemKvp.Value;
                        var volumePerItem = cargoItem.VolumePerUnit;
                        var volumeStored  = _volStorageDB.GetVolumeStored(cargoItem);
                        var massStored    = _volStorageDB.GetMassStored(cargoItem);

                        bool isSelected = selectedCargo == cargoItem;
                        if (ImGui.Selectable(cname, isSelected))
                        {
                            selectedCargo = cargoItem;
                            CargoItemSelectedEvent.Invoke(this);
                        }

                        ImGui.NextColumn();
                        ImGui.Text(Stringify.Number(unitsStored));


                        if (_cargoToMove.ContainsKey(cargoItem))
                        {
                            var    unitsMoving = _cargoToMove[cargoItem];
                            string text        = Stringify.Number(unitsMoving);
                            ImGui.SameLine();

                            float blue = 0f;
                            if (_cargoToMoveDatablob.ContainsKey(cargoItem))
                            {
                                if (_cargoToMoveDatablob[cargoItem] != 0)
                                {
                                    blue = 0.25f;
                                }
                            }
                            if (_cargoToMoveOrders.ContainsKey(cargoItem))
                            {
                                if (_cargoToMoveOrders[cargoItem] != 0)
                                {
                                    blue = 0.5f;
                                }
                            }
                            if (_cargoToMoveUI.ContainsKey(cargoItem))
                            {
                                if (_cargoToMoveUI[cargoItem] != 0)
                                {
                                    blue = 0.75f;
                                }
                            }

                            if (unitsMoving > 0)
                            {
                                ImGui.TextColored(new Vector4(0.5f, 1, blue, 1), text);
                            }
                            else
                            {
                                ImGui.TextColored(new Vector4(1f, 0.5f, blue, 1), text);
                            }
                        }

                        ImGui.NextColumn();
                        ImGui.Text(Stringify.Mass(massStored));
                        ImGui.NextColumn();
                    }

                    ImGui.Columns(1);
                }
            }


            ImGui.EndChild();
        }