VRage.MyFixedPoint ItemAmount(MyItemType type, float volume)
 {
     return(new VRage.MyFixedPoint
     {
         RawValue = (long)(volume / type.GetItemInfo().Volume)
     });
 }
Beispiel #2
0
        public long GetItemsMängi(MyItemType type)
        {
            if (!type.TypeId.Equals("MyObjectBuilder_Ingot") && !type.TypeId.Equals("MyObjectBuilder_Ore"))
            {
                var mängi = _inventories.Sum(i => (int)i.GetItemAmount(type));
                return(mängi);
            }

            var liter = _inventories.Sum(i => i.GetItemAmount(type).RawValue / 1000); //m^3 to l

            return(Convert.ToInt64(Math.Truncate((double)liter * type.GetItemInfo().Volume)));
        }
Beispiel #3
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;
                }
            }
        /// <summary>
        /// Attempts to equalize the amounts of certain item between connected inventories.
        /// </summary>
        /// <param name="invs">Collection of inventories to equalize.</param>
        /// <param name="type">Item to transfer.</param>
        public static void EqualizeItemCount(IList <IMyInventory> invs, MyItemType type)
        {
            var          info = type.GetItemInfo();
            MyFixedPoint norm = new MyFixedPoint();

            for (int idx = invs.Count - 1; idx >= 0; idx--)
            {
                norm += invs[idx].GetItemAmount(type);
            }
            if (info.UsesFractions)
            {
                norm = (MyFixedPoint)((double)norm / invs.Count);
            }
            else
            {
                norm = (MyFixedPoint)((int)norm / invs.Count);
            }

            for (int i = invs.Count - 1; i > 0; i--) // not including 0
            {
                MyFixedPoint delta = invs[i].GetItemAmount(type) - norm;
                if (delta > 0)
                {
                    for (int j = i - 1; (delta > 0) && (j >= 0); j--)
                    {
                        delta -= MoveItem(invs[i], invs[j], type, delta);
                    }
                }
                else if (delta < 0)
                {
                    for (int j = i - 1; (delta < 0) && (j >= 0); j--)
                    {
                        delta += MoveItem(invs[j], invs[i], type, -delta);
                    }
                }
            }
        }
Beispiel #5
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;
                    }
                }
            }
Beispiel #6
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;
                }
            }