public void AddChangedPhysicalInventoryItem(MyPhysicalInventoryItem intentoryItem, MyFixedPoint changedAmount, bool added)
        {
            Debug.Assert(changedAmount > 0 || (!added && changedAmount < 0));

            var definition = intentoryItem.GetItemDefinition();

            if (definition == null)
            {
                return;
            }

            if (changedAmount < 0)
            {
                changedAmount = -changedAmount;
            }
            Debug.Assert(changedAmount > 0);

            var item = new MyItemInfo()
            {
                DefinitionId  = definition.Id,
                Icons         = definition.Icons,
                TotalAmount   = intentoryItem.Amount,
                ChangedAmount = changedAmount,
                Added         = added
            };

            AddItem(item);
        }
Beispiel #2
0
        /// <param name="source">The source inventory</param>
        /// <param name="target">The target inventory</param>
        /// <param name="item">The item to be transfered</param>
        /// <param name="amount">The maximum amount to transfer</param>
        /// <returns>The amount that still needs to be transfered</returns>
        public static MyFixedPoint TransferAsMuchAsPossible(IMyInventory source, IMyInventory target, MyInventoryItem item, MyFixedPoint amount)
        {
            var        remainingVolume = target.MaxVolume - target.CurrentVolume;
            MyItemInfo itemInfo        = item.Type.GetItemInfo();

            // If at least 1% volume left
            float minEmptyVol = 0.01f;

            if (remainingVolume > target.MaxVolume * minEmptyVol)
            {
                var transferAmt = MyFixedPoint.Min(item.Amount, amount);
                var totalVolume = transferAmt * itemInfo.Volume;

                if (totalVolume > remainingVolume)
                {
                    transferAmt = remainingVolume * (1f / itemInfo.Volume);
                }

                if (!itemInfo.UsesFractions)
                {
                    transferAmt = MyFixedPoint.Floor(transferAmt);
                }

                if (source.TransferItemTo(target, item, transferAmt))
                {
                    amount -= transferAmt;
                }
            }

            return(amount);
        }
        public void AddPhysicalInventoryItem(MyPhysicalInventoryItem intentoryItem, MyFixedPoint addedAmount)
        {
            var definition = intentoryItem.GetItemDefinition();

            if (definition == null)
            {
                return;
            }

            var item = new MyItemInfo()
            {
                DefinitionId = definition.Id,
                Icon         = definition.Icon,
                TotalAmount  = intentoryItem.Amount,
                AddedAmount  = addedAmount
            };

            AddItem(item);
        }
Beispiel #4
0
            public Store(IMyInventory inv, MyItemType itemType, string description = "") : base(description)
            {
                MyItemInfo itemInfo = itemType.GetItemInfo();
                float      amount   = (float)inv.GetItemAmount(itemType);

                Max        += (float)inv.MaxVolume;
                DefaultUnit = "kL";

                if (itemInfo.UsesFractions)
                {
                    Mass    = amount;
                    Current = itemInfo.Volume * amount;
                }
                else
                {
                    Mass    = itemInfo.Mass * amount;
                    Current = itemInfo.Volume * amount;
                }
            }
        public void AddItem(MyItemInfo item)
        {
            var addedTime = MySession.Static.ElapsedGameTime.TotalSeconds;

            if (m_items.Count > 0)
            {
                var lastItem = m_items[m_items.Count - 1];
                // Added the same item as last one?
                if (lastItem.DefinitionId == item.DefinitionId)
                {
                    lastItem.AddedAmount += item.AddedAmount;
                    lastItem.TotalAmount  = item.TotalAmount;

                    if (m_items.Count <= GROUP_ITEMS_COUNT)
                    {
                        lastItem.RemoveTime = addedTime + TIME_TO_REMOVE_ITEM_SEC;
                    }

                    m_items[m_items.Count - 1] = lastItem;

                    return;
                }
                else
                {
                    if (m_items.Count >= GROUP_ITEMS_COUNT)
                    {
                        int prevGroupIndex = m_items.Count - GROUP_ITEMS_COUNT;
                        Debug.Assert(prevGroupIndex >= 0 && prevGroupIndex < m_items.Count);
                        var prevGroupItem = m_items[prevGroupIndex];
                        var nextGroupTime = prevGroupItem.AddTime + TIME_TO_REMOVE_ITEM_SEC;
                        addedTime = Math.Max(addedTime, nextGroupTime);
                    }
                }
            }

            item.AddTime    = addedTime;
            item.RemoveTime = addedTime + TIME_TO_REMOVE_ITEM_SEC;
            m_items.Add(item);
        }
        static ItemType ParseType(MyInventoryItem item)
        {
            MyItemInfo info = item.Type.GetItemInfo();

            if (info.IsOre)
            {
                return(ItemType.Ore);
            }
            if (info.IsIngot)
            {
                return(ItemType.Ingot);
            }
            if (info.IsComponent)
            {
                return(ItemType.Component);
            }
            if (info.IsAmmo)
            {
                return(ItemType.Ammunition);
            }
            return(ItemType.Other);
        }
        private void AddItem(MyItemInfo item)
        {
            var addedTime = MySession.Static.ElapsedGameTime.TotalSeconds;

            if (m_items.Count > 0)
            {
                var lastItem = m_items[m_items.Count - 1];
                // Added the same item as last one?
                if (lastItem.DefinitionId == item.DefinitionId && lastItem.Added == item.Added)
                {
                    lastItem.ChangedAmount += item.ChangedAmount;
                    lastItem.TotalAmount = item.TotalAmount;

                    if (m_items.Count <= GROUP_ITEMS_COUNT)
                        lastItem.RemoveTime = addedTime + TIME_TO_REMOVE_ITEM_SEC;

                    m_items[m_items.Count - 1] = lastItem;

                    return;
                }
                else
                {
                    if (m_items.Count >= GROUP_ITEMS_COUNT)
                    {
                        int prevGroupIndex = m_items.Count - GROUP_ITEMS_COUNT;
                        Debug.Assert(prevGroupIndex >= 0 && prevGroupIndex < m_items.Count);
                        var prevGroupItem = m_items[prevGroupIndex];
                        var nextGroupTime = prevGroupItem.AddTime + TIME_TO_REMOVE_ITEM_SEC;
                        addedTime = Math.Max(addedTime, nextGroupTime);
                    }
                }
            }

            item.AddTime = addedTime;
            item.RemoveTime = addedTime + TIME_TO_REMOVE_ITEM_SEC;
            m_items.Add(item);
        }
Beispiel #8
0
            public Store(IMyEntity entity, MyItemType itemType, string description = "") : base(description)
            {
                for (int i = 0; i < entity.InventoryCount; i++)
                {
                    IMyInventory inv = entity.GetInventory(i);

                    MyItemInfo itemInfo = itemType.GetItemInfo();
                    float      amount   = (float)inv.GetItemAmount(itemType);

                    Max        += (float)inv.MaxVolume;
                    DefaultUnit = "kL";

                    if (itemInfo.UsesFractions)
                    {
                        Mass    += amount;
                        Current += itemInfo.Volume * amount;
                    }
                    else
                    {
                        Mass    += itemInfo.Mass * amount;
                        Current += itemInfo.Volume * amount;
                    }
                }
            }
        public void AddChangedPhysicalInventoryItem(MyPhysicalInventoryItem intentoryItem, MyFixedPoint changedAmount, bool added)
        {
            Debug.Assert(changedAmount > 0 || (!added && changedAmount < 0));

            var definition = intentoryItem.GetItemDefinition();
            if (definition == null)
                return;

            if (changedAmount < 0)
                changedAmount = -changedAmount;
            Debug.Assert(changedAmount > 0);

            var item = new MyItemInfo()
            {
                DefinitionId = definition.Id,
                Icons = definition.Icons,
                TotalAmount = intentoryItem.Amount,
                ChangedAmount = changedAmount,
                Added = added
            };

            AddItem(item);
        }
        public void AddPhysicalInventoryItem(MyPhysicalInventoryItem intentoryItem, MyFixedPoint addedAmount)
        {
            var definition = intentoryItem.GetItemDefinition();
            if (definition == null)
                return;

            var item = new MyItemInfo()
            {
                DefinitionId = definition.Id,
                Icon = definition.Icon,
                TotalAmount = intentoryItem.Amount,
                AddedAmount = addedAmount
            };

            AddItem(item);
        }
Beispiel #11
0
            public ItemTypeDescriptor(MyItemType type, double value = 0)
            {
                Amount = value;
                Type   = type;
                Info   = type.GetItemInfo();
                if (Type.TypeId == "MyObjectBuilder_GasProperties")
                {
                    Category = (Type.SubtypeId == "Electricity") ? ItemCategory.None : ItemCategory.Gas;
                }
                else if (Info.IsOre)
                {
                    Category = ItemCategory.Ore;
                }
                else if (Info.IsIngot)
                {
                    Category = ItemCategory.Ingot;
                }
                else if (Info.IsAmmo)
                {
                    Category = ItemCategory.Ammo;
                }
                else if (Info.IsComponent)
                {
                    Category = ItemCategory.Component;
                }
                else if (Info.IsTool)
                {
                    Category = ItemCategory.Tool;
                }
                else
                {
                    Category = ItemCategory.Other;
                }
                if (Type.TypeId == "MyObjectBuilder_GasProperties")
                {
                    Units = new string[] { "L ", "kL", "ML" }
                }
                ;
                else if (Info.UsesFractions)
                {
                    Units = new string[] { "kg", "t ", "kt" }
                }
                ;
                else
                {
                    Units = new string[] { "", "K", "M" }
                };
                switch (Category)
                {
                case ItemCategory.Ore:
                    switch (Type.SubtypeId)
                    {
                    case "Scrap":
                    case "Stone":
                    case "Ice":
                    case "Organic": Name = Type.SubtypeId; break;

                    default: Name = $"{Type.SubtypeId} Ore"; break;
                    }
                    ; break;

                case ItemCategory.Ingot:
                    switch (Type.SubtypeId)
                    {
                    case "Stone": Name = "Gravel"; break;

                    case "Magnesium": Name = "Magnesium Powder"; break;

                    case "Silicon": Name = "Silicon Wafer"; break;

                    default: Name = $"{Type.SubtypeId} Ingot"; break;
                    }
                    ; break;

                case ItemCategory.Component:
                    switch (Type.SubtypeId)
                    {
                    case "SmallTube": Name = "Small Tube"; break;

                    case "LargeTube": Name = "Large Tube"; break;

                    default: Name = Type.SubtypeId; break;
                    }
                    ; break;

                default:
                    Name = Type.SubtypeId; break;
                }
            }