Beispiel #1
0
        public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1)
        {
            var maxAmount  = ComputeAmountThatFits(objectBuilder.GetId());
            var restAmount = amount;

            if (amount <= maxAmount)
            {
                foreach (MyInventoryBase inventory in m_children.Reader)
                {
                    var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId());
                    if (availableSpace > restAmount)
                    {
                        availableSpace = restAmount;
                    }
                    if (availableSpace > 0)
                    {
                        if (inventory.AddItems(availableSpace, objectBuilder))
                        {
                            restAmount -= availableSpace;
                        }
                    }
                }
            }
            return(restAmount == 0);
        }
Beispiel #2
0
        public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder)
        {
            MyFixedPoint point  = this.ComputeAmountThatFits(objectBuilder.GetId(), 0f, 0f);
            MyFixedPoint point2 = amount;

            if (amount <= point)
            {
                foreach (MyInventoryBase base2 in this.m_children.Reader)
                {
                    MyFixedPoint point3 = base2.ComputeAmountThatFits(objectBuilder.GetId(), 0f, 0f);
                    if (point3 > point2)
                    {
                        point3 = point2;
                    }
                    if ((point3 > 0) && base2.AddItems(point3, objectBuilder))
                    {
                        point2 -= point3;
                    }
                    if (point2 == 0)
                    {
                        break;
                    }
                }
            }
            return(point2 == 0);
        }
        private bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1)
        {
            if (amount == 0) return false;
            Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject || (MyFakes.ENABLE_COMPONENT_BLOCKS && objectBuilder is MyObjectBuilder_CubeBlock), "This type of inventory can't add other types than PhysicalObjects!");

            MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject;
            MyDefinitionId defId = objectBuilder.GetId();
            if (MyFakes.ENABLE_COMPONENT_BLOCKS)
            {
                if (physicalObjectBuilder == null)
                {
                    physicalObjectBuilder = new MyObjectBuilder_BlockItem();
                    (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = defId;
                }
                else
                {
                    MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(defId);
                    if (blockDef != null)
                    {
                        physicalObjectBuilder = new MyObjectBuilder_BlockItem();
                        (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id;
                    }
                }
            }

            if (physicalObjectBuilder == null)
                return false;

            defId = physicalObjectBuilder.GetObjectId();
            MyFixedPoint fittingAmount = ComputeAmountThatFits(defId);

            if (fittingAmount < amount) return false;

            if (Sync.IsServer)
            {
                if (MyPerGameSettings.ConstrainInventory())
                    AffectAddBySurvival(ref amount, physicalObjectBuilder);
                if (amount == 0)
                    return false;
                AddItemsInternal(amount, physicalObjectBuilder, itemId, index);
            }
            return true;
        }
 public override bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1)
 {
     var maxAmount = ComputeAmountThatFits(objectBuilder.GetId());
     var restAmount = amount;
     if (amount <= maxAmount)
     {
         foreach (MyInventoryBase inventory in m_children.Reader)
         {
             var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId());
             if (availableSpace > restAmount)
             {
                 availableSpace = restAmount;
             }
             if (availableSpace > 0)
             {
                 if (inventory.AddItems(availableSpace, objectBuilder))
                 {
                     restAmount -= availableSpace;
                 }
             }
         }
     }
     return restAmount == 0;
 }
Beispiel #5
0
 public static string GetDisplayName(this MyObjectBuilder_Base objectBuilder)
 {
     return(MyDefinitionManager.Static.GetDefinition(objectBuilder.GetId()).GetDisplayName());
 }
Beispiel #6
0
        public static bool FindFreeCargo(MyCubeBlock startBlock, MyObjectBuilder_Base item, int count, bool order = true)
        {
            var list = Conveyor.GetConveyorListFromEntity(startBlock);

            if (list == null)
            {
                Logging.Instance.WriteLine(string.Format("Conveyor list is null!"));
                return(false);
            }

            if (!list.Contains(startBlock.EntityId))
            {
                list.Add(startBlock.EntityId);
            }

            List <MyInventory> inventoryList = new List <MyInventory>();

            foreach (var inventoryItem in list)
            {
                IMyEntity entity;
                if (MyAPIGateway.Entities.TryGetEntityById(inventoryItem, out entity))
                {
                    if (!(entity is IMyCubeBlock))
                    {
                        continue;
                    }

                    if (entity is Ingame.IMyRefinery || entity is Ingame.IMyAssembler)
                    {
                        continue;
                    }

                    MyCubeBlock block = (MyCubeBlock)entity;
                    if (!block.HasInventory)
                    {
                        continue;
                    }

                    if (block.EntityId == startBlock.EntityId)
                    {
                        inventoryList.Insert(0, block.GetInventory());
                    }
                    else
                    {
                        inventoryList.Add(block.GetInventory());
                    }
                }
            }

            MyInventory targetInventory = null;

            List <MyInventory> modifiedList;

            if (order)
            {
                modifiedList = inventoryList.OrderByDescending(x => (float)x.MaxVolume - (float)x.CurrentVolume).ToList();
            }
            else
            {
                modifiedList = inventoryList;
            }

            foreach (var inventoryItem in modifiedList)
            {
                targetInventory = inventoryItem;
                if (targetInventory.CanItemsBeAdded(count, item.GetId()))
                {
                    var ownerName = targetInventory.Owner as IMyTerminalBlock;
                    if (ownerName != null)
                    {
                        Logging.Instance.WriteLine(string.Format("TRANSFER Adding {0} {1} to {2}", count, item.GetId().SubtypeName, ownerName.CustomName));
                    }

                    targetInventory.AddItems(count, item);
                    return(true);
                }
            }

            return(false);
        }
        public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1, bool stack = true)
        {
            Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!");
            MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject;
            if (physicalObjectBuilder == null)
            {
                return false;
            }
            if (amount == 0) return false;
            if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId())) return false;

            if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID)
            {
                MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(objectBuilder.GetId());
                if (blockDef != null)
                {
                    physicalObjectBuilder = new MyObjectBuilder_BlockItem();
                    (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id;
                }
            }

            if (Sync.IsServer)
            {
                if (MyPerGameSettings.ConstrainInventory())
                    AffectAddBySurvival(ref amount, physicalObjectBuilder);
                if (amount == 0)
                    return false;
                AddItemsInternal(amount, physicalObjectBuilder, index, itemId, stack);

            }
            return true;
        }
 virtual public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, int index = -1)
 {
     var maxAmount = ComputeAmountThatFits(objectBuilder.GetId());
     var restAmount = amount;
     if (amount <= maxAmount)
     {
         foreach (var inventory in Inventories)
         {
             var availableSpace = inventory.ComputeAmountThatFits(objectBuilder.GetId());
             if (availableSpace > restAmount)
             {
                 availableSpace = restAmount;
             }
             if (inventory.AddItems(availableSpace, objectBuilder))
             {
                 restAmount -= availableSpace;
             }
         }
     }
     return restAmount == 0;
 }