Пример #1
0
        private static void ItemPullAllInternal(MyInventory destinationInventory, PullRequestItemSet requestedTypeIds, bool onlySmall)
        {
            SetTraversalInventoryItemDefinitionId();
            Debug.Assert(m_tmpPullRequests.Count == 0, "m_tmpPullRequests is not empty!");
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
                {
                    IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
                    if (owner == null) continue;

                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        var inventory = owner.GetInventory(i);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                            continue;

                        if (inventory == destinationInventory)
                            continue;

                        m_tmpInventoryItems.Clear();
                        foreach (var item in inventory.GetItems())
                        {
                            m_tmpInventoryItems.Add(item);
                        }

                        foreach (var item in m_tmpInventoryItems)
                        {
                            if (destinationInventory.VolumeFillFactor >= 1.0f)
                            {
                                m_tmpInventoryItems.Clear();
                                return;
                            }

                            var itemId = item.Content.GetId();

                            if (requestedTypeIds != null && !requestedTypeIds.Contains(itemId))
                                continue;

                            if (onlySmall && NeedsLargeTube(itemId))
                                continue;

                            var transferedAmount = item.Amount;

                            var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_OxygenContainerObject;
                            if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f)
                                continue;

                            if (!MySession.Static.CreativeMode)
                            {
                                var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                                {
                                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                                }
                                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
                            }
                            if (transferedAmount == 0)
                                continue;

                            // SK: this is mental
                            m_tmpPullRequests.Add(new MyTuple<IMyConveyorEndpointBlock, MyPhysicalInventoryItem>(m_startingEndpoint.CubeBlock as IMyConveyorEndpointBlock, item));
                            //MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);
                        }
                    }
                }
            }

            foreach (var tuple in m_tmpPullRequests)
            {
                if (destinationInventory.VolumeFillFactor >= 1.0f)
                {
                    m_tmpPullRequests.Clear();
                    return;
                }

                var start = tuple.Item1;
                var item = tuple.Item2;

                var transferedAmount = item.Amount;
                var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                {
                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                }
                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);

                if (transferedAmount == 0)
                    continue;

                var itemId = item.Content.GetId();

                SetTraversalInventoryItemDefinitionId(itemId);
                ItemPullRequest(start, destinationInventory, m_playerIdForAccessiblePredicate, itemId, transferedAmount);
            }

            m_tmpPullRequests.Clear();
        }
        private static bool ItemPullAllInternal(MyInventory destinationInventory, PullRequestItemSet requestedTypeIds, bool onlySmall)
        {
            bool pullCreated = false;

            SetTraversalInventoryItemDefinitionId();
            Debug.Assert(m_tmpPullRequests.Count == 0, "m_tmpPullRequests is not empty!");
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
                {
                    MyCubeBlock owner = (conveyorEndpoint.CubeBlock != null && conveyorEndpoint.CubeBlock.HasInventory) ? conveyorEndpoint.CubeBlock : null;
                    if (owner == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        var inventory = owner.GetInventory(i) as MyInventory;
                        System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!");

                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                        {
                            continue;
                        }

                        if (inventory == destinationInventory)
                        {
                            continue;
                        }

                        m_tmpInventoryItems.Clear();
                        foreach (var item in inventory.GetItems())
                        {
                            m_tmpInventoryItems.Add(item);
                        }

                        foreach (var item in m_tmpInventoryItems)
                        {
                            if (destinationInventory.VolumeFillFactor >= 1.0f)
                            {
                                m_tmpInventoryItems.Clear();
                                return(pullCreated);
                            }

                            var itemId = item.Content.GetId();

                            if (requestedTypeIds != null && !requestedTypeIds.Contains(itemId))
                            {
                                continue;
                            }

                            if (onlySmall && NeedsLargeTube(itemId))
                            {
                                continue;
                            }

                            var transferedAmount = item.Amount;

                            var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_GasContainerObject;
                            if (oxygenBottle != null && oxygenBottle.GasLevel == 1f)
                            {
                                continue;
                            }

                            if (!MySession.Static.CreativeMode)
                            {
                                var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                                {
                                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                                }
                                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
                            }
                            if (transferedAmount == 0)
                            {
                                continue;
                            }

                            // SK: this is mental
                            m_tmpPullRequests.Add(new MyTuple <IMyConveyorEndpointBlock, MyPhysicalInventoryItem>(m_startingEndpoint.CubeBlock as IMyConveyorEndpointBlock, item));
                            //MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);
                        }
                    }
                }
            }

            foreach (var tuple in m_tmpPullRequests)
            {
                if (destinationInventory.VolumeFillFactor >= 1.0f)
                {
                    m_tmpPullRequests.Clear();
                    return(pullCreated);
                }

                var start = tuple.Item1;
                var item  = tuple.Item2;

                var transferedAmount = item.Amount;
                var fittingAmount    = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                {
                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                }
                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);

                if (transferedAmount == 0)
                {
                    continue;
                }

                var itemId = item.Content.GetId();

                SetTraversalInventoryItemDefinitionId(itemId);
                ItemPullRequest(start, destinationInventory, m_playerIdForAccessiblePredicate, itemId, transferedAmount);
                pullCreated = true;
            }

            m_tmpPullRequests.Clear();
            return(pullCreated);
        }