• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IMyConveyorEndpointBlock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IMyConveyorEndpointBlock的典型用法代码示例。如果您正苦于以下问题:C# IMyConveyorEndpointBlock类的具体用法?C# IMyConveyorEndpointBlock怎么用?C# IMyConveyorEndpointBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IMyConveyorEndpointBlock类属于命名空间,在下文中一共展示了IMyConveyorEndpointBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Init

			public void Init(MyDefinitionId typeId, IMyConveyorEndpointBlock block)
			{
				FirstEndpoint = block.ConveyorEndpoint;
				ClearData();

				Add(typeId, block);
			}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:7,代码来源:MyResourceDistributorComponent.cs


示例2: MyPhysicalDistributionGroup

			public MyPhysicalDistributionGroup(MyDefinitionId typeId, IMyConveyorEndpointBlock block)
			{
			    SinksByPriority = null; SourcesByPriority = null; SinkSourcePairs = null; FirstEndpoint = null;
				SinkDataByPriority = null; SourceDataByPriority = null; StockpilingStorage = null; OtherStorage = null;
				InputOutputData = new MyTuple<MySinkGroupData, MySourceGroupData>();
				MaxAvailableResources = 0f; ResourceState = MyResourceStateEnum.NoPower;
				AllocateData();

				Init(typeId, block);
			}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:10,代码来源:MyResourceDistributorComponent.cs


示例3: RemoveConveyorBlock

        public void RemoveConveyorBlock(IMyConveyorEndpointBlock block)
        {
            if (block is MyShipConnector)
                m_connectors.Remove(block as MyShipConnector);

            if (IsClosing) return;

            for (int i = 0; i < block.ConveyorEndpoint.GetLineCount(); ++i)
            {
                MyConveyorLine line = block.ConveyorEndpoint.GetConveyorLine(i);
                line.DisconnectEndpoint(block.ConveyorEndpoint);

                if (line.IsDegenerate)
                    m_lines.Remove(line);
            }
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:16,代码来源:MyGridConveyorSystem.cs


示例4: Add

			public void Add(MyDefinitionId typeId, IMyConveyorEndpointBlock endpoint)
			{
                if (FirstEndpoint == null)
                    FirstEndpoint = endpoint.ConveyorEndpoint;

				var componentContainer = (endpoint as IMyEntity).Components;

                var sink = componentContainer.Get<MyResourceSinkComponent>();
                var source = componentContainer.Get<MyResourceSourceComponent>();

                bool containsSink = sink != null && sink.AcceptedResources.Contains(typeId);
                bool containsSource = source != null && source.ResourceTypes.Contains(typeId);
                if (containsSink && containsSource)
                {
                    SinkSourcePairs.Add(new MyTuple<MyResourceSinkComponent, MyResourceSourceComponent>(sink, source));
                }
                else if (containsSink)
                {
                    SinksByPriority[GetPriority(sink)].Add(sink);
                }
                else if (containsSource)
                {
                    SourcesByPriority[GetPriority(source)].Add(source);
                }
			}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:25,代码来源:MyResourceDistributorComponent.cs


示例5: ItemPullAll

        private static bool ItemPullAll(IMyConveyorEndpointBlock start, MyInventory destinationInventory)
        {
            MyCubeBlock startingBlock = start as MyCubeBlock;
            if (startingBlock == null) return false;

            bool itemsPulled = false;

            // Try and get the block from the cache
            MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
            MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
            if (endpoints.pullElements != null)
            {
                // Iterate to the other elements, see if we can collect some amount of items to pull
                for (int i = 0; i < endpoints.pullElements.Count; i++)
                {
                    MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
                    if (sourceBlock == null) continue;

                    int inventoryCount = sourceBlock.InventoryCount;
                    for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
                    {
                        MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                            continue;

                        if (inventory == destinationInventory)
                            continue;

                        var items = inventory.GetItems().ToArray();
                        for (int itemIndex = 0; itemIndex < items.Length; itemIndex++)
                        {
                            var item = items[itemIndex];
                            var itemId = item.GetDefinitionId();

                            var amountThatFits = destinationInventory.ComputeAmountThatFits(itemId);
                            if (amountThatFits <= 0)
                                continue;

                            // Verify that this item can, in fact, make it past sorters, etc
                            if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
                                continue;

                            var availableAmount = inventory.GetItemAmount(itemId);
                            var transferAmount = MyFixedPoint.Min(availableAmount, amountThatFits);

                            MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, transferAmount);
                            itemsPulled = true;

                            if (destinationInventory.CargoPercentage >= 0.99f)
                                break;
                        }

                        if (destinationInventory.CargoPercentage >= 0.99f)
                            break;
                    }

                    if (destinationInventory.CargoPercentage >= 0.99f)
                        break;
                }
            }

            else
            {
                // Cache may need to be recomputed
                if (!conveyorSystem.m_isRecomputingGraph)
                    conveyorSystem.RecomputeConveyorEndpoints();
            }
            return itemsPulled;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:69,代码来源:MyGridConveyorSystem.cs


示例6: PullAllRequest

        public static bool PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyInventoryConstraint requestedTypeIds)
        {
            MyCubeBlock startingBlock = start as MyCubeBlock;
            if (startingBlock == null) return false;

            m_tmpRequestedItemSet.Set(requestedTypeIds);

            // Try and get the block from the cache
            MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
            MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
            if (endpoints.pullElements != null)
            {
                bool didTransfer = false;

                // Iterate to the other elements, see if we can collect some amount of items to pull
                for (int i = 0; i < endpoints.pullElements.Count; i++)
                {
                    MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
                    if (sourceBlock == null) continue;

                    int inventoryCount = sourceBlock.InventoryCount;
                    for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
                    {
                        MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
                        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 true;
                            }

                            var itemId = item.Content.GetId();

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

                            // Verify that this item can, in fact, make it past sorters, etc
                            if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
                                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;

                            didTransfer = true;
                            MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);

                            if (destinationInventory.CargoPercentage >= 0.99f)
                                break;
                        }

                        if (destinationInventory.CargoPercentage >= 0.99f)
                            break;
                    }

                    if (destinationInventory.CargoPercentage >= 0.99f)
                        break;
                }

                return didTransfer;
            }

            else
            {
                // Cache may need to be recomputed
                if (!conveyorSystem.m_isRecomputingGraph)
                    conveyorSystem.RecomputeConveyorEndpoints();
            }

            return false;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:99,代码来源:MyGridConveyorSystem.cs


示例7: TryMergeEndpointSegment

        /// <summary>
        /// Tries to merge the conveyor lines of a conveyor block and segment block.
        /// Also changes the reference in the endpoint block to the correct line.
        /// </summary>
        private bool TryMergeEndpointSegment(IMyConveyorEndpointBlock endpoint, IMyConveyorSegmentBlock segmentBlock, ConveyorLinePosition endpointPosition)
        {
            MyConveyorLine endpointLine = endpoint.ConveyorEndpoint.GetConveyorLine(endpointPosition);
            if (endpointLine == null) return false;

            // The conveyor segment cannot merge with the given endpoint
            if (!segmentBlock.ConveyorSegment.CanConnectTo(endpointPosition.GetConnectingPosition(), endpointLine.Type))
                return false;

            MyConveyorLine segmentLine = segmentBlock.ConveyorSegment.ConveyorLine;

            segmentLine.Merge(endpointLine, segmentBlock);
            endpoint.ConveyorEndpoint.SetConveyorLine(endpointPosition, segmentLine);
            endpointLine.RecalculateConductivity();
            segmentLine.RecalculateConductivity();
            return true;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:21,代码来源:MyGridConveyorSystem.cs


示例8: AddConveyorBlock

        public void AddConveyorBlock(IMyConveyorEndpointBlock endpointBlock)
        {
            // Invalidate iterator and add block
            m_endpointIterator = null;
            m_conveyorEndpointBlocks.Add(endpointBlock);

            if (endpointBlock is MyShipConnector)
                m_connectors.Add(endpointBlock as MyShipConnector);

            m_tmpConveyorPositionList.Clear();
            var endpoint = endpointBlock.ConveyorEndpoint;

            for (int i = 0; i < endpoint.GetLineCount(); ++i)
            {
                var position = endpoint.GetPosition(i);
                var line = endpoint.GetConveyorLine(i);

                if (m_deserializedLines != null && m_deserializedLines.Contains(line))
                    continue;

                var otherBlock = m_grid.GetCubeBlock(position.NeighbourGridPosition);
                if (otherBlock == null)
                {
                    m_lines.Add(line);
                    continue;
                }

                var otherEndpointBlock = otherBlock.FatBlock as IMyConveyorEndpointBlock;
                var otherSegmentBlock = otherBlock.FatBlock as IMyConveyorSegmentBlock;

                if (otherSegmentBlock != null)
                {
                    if (!TryMergeEndpointSegment(endpointBlock, otherSegmentBlock, position))
                    {
                        m_lines.Add(line);
                    }
                }
                else if (otherEndpointBlock != null)
                {
                    if (!TryMergeEndpointEndpoint(endpointBlock, otherEndpointBlock, position, position.GetConnectingPosition()))
                    {
                        m_lines.Add(line);
                    }
                }
                else
                {
                    m_lines.Add(line);
                }
            }
            m_tmpConveyorPositionList.Clear();
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:51,代码来源:MyGridConveyorSystem.cs


示例9: CanTransfer

        private static bool CanTransfer(IMyConveyorEndpointBlock start, IMyConveyorEndpointBlock endPoint, MyDefinitionId itemId, bool isPush)
        {
            MyGridConveyorSystem conveyorSystem = (start as MyCubeBlock).CubeGrid.GridSystems.ConveyorSystem;
            MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);

            // Verify that this item can, in fact, make it past sorters, etc
            bool canTransfer = true;
            if (endpoints.TryGetTransfer(endPoint, itemId, false, out canTransfer))
            {
                return canTransfer;
            }
            else
            {
                Tuple<IMyConveyorEndpointBlock, IMyConveyorEndpointBlock> tuple = new Tuple<IMyConveyorEndpointBlock, IMyConveyorEndpointBlock>(start, endPoint);
                lock (m_currentTransferComputationTasks)
                {
                    if (!m_currentTransferComputationTasks.ContainsKey(tuple))
                    {
                        TransferData transferData = new TransferData(start, endPoint, itemId, isPush);
                        ParallelTasks.Task task = ParallelTasks.Parallel.Start(ComputeTransferData, OnTransferDataComputed, transferData);
                        m_currentTransferComputationTasks.Add(tuple, task);
                    }
                }
                return false;
            }
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:26,代码来源:MyGridConveyorSystem.cs


示例10: ItemPushRequest

        public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint? amount = null)
        {
            var itemBuilder = toSend.Content;
            if (amount.HasValue)
                Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) ||
                                toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) ||
                                MyFixedPoint.Floor(amount.Value) == amount.Value);

            MyFixedPoint remainingAmount = toSend.Amount;
            if (amount.HasValue)
            {
                remainingAmount = amount.Value;
            }

            SetTraversalPlayerId(playerId);

            var toSendContentId = toSend.Content.GetId();
            SetTraversalInventoryItemDefinitionId(toSendContentId);

            if (NeedsLargeTube(toSendContentId))
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate);
            }
            else
            {
                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate);
            }

            bool success = false;

            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.CanReceive) == 0)
                        continue;

                    if (inventory == srcInventory)
                        continue;

                    var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId);
                    fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount);
                    if (!inventory.CheckConstraint(toSendContentId))
                        continue;
                    if (fittingAmount == 0)
                        continue;

                    MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount);
                    success = true;
                }
            }
            return success;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:57,代码来源:MyGridConveyorSystem.cs


示例11: PushAnyRequest

        public static void PushAnyRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId)
        {
            if (srcInventory.Empty())
                return;

            // try all items and stop on first successfull
            foreach (var item in srcInventory.GetItems())
            {
                if (ItemPushRequest(start, srcInventory, playerId, item))
                    return;
            }
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:12,代码来源:MyGridConveyorSystem.cs


示例12: ItemPullRequest

        public static void ItemPullRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId, MyFixedPoint? amount = null)
        {
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                if (amount.HasValue)
                    Debug.Assert(itemId.TypeId == typeof(MyObjectBuilder_Ore) ||
                                 itemId.TypeId == typeof(MyObjectBuilder_Ingot) ||
                                 MyFixedPoint.Floor(amount.Value) == amount.Value);

                SetTraversalPlayerId(playerId);
                SetTraversalInventoryItemDefinitionId(itemId);

                PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null);
                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;

                        if (amount.HasValue)
                        {
                            var availableAmount = inventory.GetItemAmount(itemId);
                            availableAmount = amount.HasValue ? MyFixedPoint.Min(availableAmount, amount.Value) : availableAmount;
                            if (availableAmount == 0)
                                continue;

                            MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount);

                            amount -= availableAmount;
                            if (amount.Value == 0)
                                return;
                        }
                        else
                        {
                            MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None);
                        }
                    }
                }
            }
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:48,代码来源:MyGridConveyorSystem.cs


示例13: ItemPullAll

 private static void ItemPullAll(IMyConveyorEndpointBlock start, MyInventory destinationInventory)
 {
     // First, search through small conveyor tubes and request only small items
     PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate);
     ItemPullAllInternal(destinationInventory, m_tmpRequestedItemSet, true);
     // Then, search again through all tubes and request all items
     PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate);
     ItemPullAllInternal(destinationInventory, m_tmpRequestedItemSet, false);
 }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:9,代码来源:MyGridConveyorSystem.cs


示例14: PullAllRequest

 public static void PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyObjectBuilderType? typeId = null)
 {
     SetTraversalPlayerId(playerId);
     m_tmpRequestedItemSet.Set(typeId);
     ItemPullAll(start, destinationInventory);
     m_tmpRequestedItemSet.Clear();
 }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:7,代码来源:MyGridConveyorSystem.cs


示例15: ComputeMappingForBlock

        private ConveyorEndpointMapping ComputeMappingForBlock(IMyConveyorEndpointBlock processedBlock)
        {
            ConveyorEndpointMapping endpointMap = new ConveyorEndpointMapping();

            // Process pull mapping
            PullInformation pullInformation = processedBlock.GetPullInformation();
            if (pullInformation != null)
            {
                endpointMap.pullElements = new List<IMyConveyorEndpointBlock>();

                lock (Pathfinding)
                {
                    SetTraversalPlayerId(pullInformation.OwnerID);

                    // Pulling one specific item?
                    if (pullInformation.ItemDefinition != default(MyDefinitionId))
                    {
                        SetTraversalInventoryItemDefinitionId(pullInformation.ItemDefinition);

                        using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
                        {
                            PrepareTraversal(processedBlock.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(pullInformation.ItemDefinition) ? IsConveyorLargePredicate : null);
                            foreach (var conveyorEndpoint in Pathfinding)
                            {
                                // Ignore endpoints without a block
                                if (conveyorEndpoint.CubeBlock == null) continue;

                                // Ignore blocks without inventory
                                if (!conveyorEndpoint.CubeBlock.HasInventory) continue;

                                // Ignore blocks that do not implement IMyConveyorEndpointBlock interface
                                IMyConveyorEndpointBlock endpointBlock = conveyorEndpoint.CubeBlock as IMyConveyorEndpointBlock;
                                if (endpointBlock == null) continue;

                                // Iterate inventories to make sure we can take the items
                                bool isInventoryAvailable = false;
                                for (int i = 0; i < conveyorEndpoint.CubeBlock.InventoryCount; ++i)
                                {
                                    var inventory = conveyorEndpoint.CubeBlock.GetInventory(i) as MyInventory;
                                    System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!");

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

                                    isInventoryAvailable = true;
                                    break;
                                }

                                if (isInventoryAvailable)
                                    endpointMap.pullElements.Add(endpointBlock);
                            }
                        }
                    }

                    else if (pullInformation.Constraint != null)
                    {
                        SetTraversalInventoryItemDefinitionId();
                        using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
                        {
                            // Once for small tubes
                            PrepareTraversal(processedBlock.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorSmallPredicate);
                            foreach (var conveyorEndpoint in Pathfinding)
                            {
                                // Ignore originating block
                                if (conveyorEndpoint.CubeBlock == processedBlock as MyCubeBlock) continue;

                                // Ignore endpoints without a block
                                if (conveyorEndpoint.CubeBlock == null) continue;

                                // Ignore blocks without inventory
                                if (!conveyorEndpoint.CubeBlock.HasInventory) continue;

                                // Ignore blocks that do not implement IMyConveyorEndpointBlock interface
                                IMyConveyorEndpointBlock endpointBlock = conveyorEndpoint.CubeBlock as IMyConveyorEndpointBlock;
                                if (endpointBlock == null) continue;

                                // Iterate inventories to make sure we can take the items
                                bool isInventoryAvailable = false;
                                for (int i = 0; i < conveyorEndpoint.CubeBlock.InventoryCount; ++i)
                                {
                                    var inventory = conveyorEndpoint.CubeBlock.GetInventory(i) as MyInventory;
                                    System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!");

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

                                    isInventoryAvailable = true;
                                    break;
                                }

                                if (isInventoryAvailable)
                                    endpointMap.pullElements.Add(endpointBlock);
                            }

                            // Once for large tubes
                            PrepareTraversal(processedBlock.ConveyorEndpoint, null, IsAccessAllowedPredicate, null);
                            foreach (var conveyorEndpoint in Pathfinding)
                            {
                                // Ignore originating block
                                if (conveyorEndpoint.CubeBlock == processedBlock as MyCubeBlock) continue;
//.........这里部分代码省略.........
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridConveyorSystem.cs


示例16: GetConveyorEndpointMapping

 public ConveyorEndpointMapping GetConveyorEndpointMapping(IMyConveyorEndpointBlock block)
 {
     if (m_conveyorConnections.ContainsKey(block))
         return m_conveyorConnections[block];
     return new ConveyorEndpointMapping();
 }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:6,代码来源:MyGridConveyorSystem.cs


示例17: ItemPullRequest

        public static MyFixedPoint ItemPullRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId, MyFixedPoint? amount = null, bool remove = false)
        {
            MyCubeBlock startingBlock = start as MyCubeBlock;
            if (startingBlock == null) return 0;

            MyFixedPoint transferred = 0;
            
            // Try and get the block from the cache
            MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
            MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
            if (endpoints.pullElements != null)
            {
                // Iterate to the other elements, see if we can collect some amount of items to pull
                for (int i = 0; i < endpoints.pullElements.Count; i++)
                {
                    MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
                    if (sourceBlock == null) continue;

                    int inventoryCount = sourceBlock.InventoryCount;
                    for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
                    {
                        MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                            continue;

                        if (inventory == destinationInventory)
                            continue;

                        // Verify that this item can, in fact, make it past sorters, etc
                        if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
                            continue;

                        var availableAmount = inventory.GetItemAmount(itemId);
                        if (amount.HasValue)
                        {
                            availableAmount = amount.HasValue ? MyFixedPoint.Min(availableAmount, amount.Value) : availableAmount;
                            if (availableAmount == 0)
                                continue;

                            if (remove)
                            {
                                transferred += inventory.RemoveItemsOfType(availableAmount, itemId);
                            }
                            else
                            {
                                transferred += MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount);
                            }

                            amount -= availableAmount;
                            if (amount.Value == 0)
                                return transferred;
                        }
                        else
                        {
                            if (remove)
                            {
                                transferred += inventory.RemoveItemsOfType(availableAmount, itemId);
                            }
                            else
                            {
                                transferred += MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, availableAmount);
                            }
                        }

                        if (destinationInventory.CargoPercentage >= 0.99f)
                            break;
                    }

                    if (destinationInventory.CargoPercentage >= 0.99f)
                        break;
                }
            }

            else
            {
                // Cache may need to be recomputed
                if (!conveyorSystem.m_isRecomputingGraph)
                    conveyorSystem.RecomputeConveyorEndpoints();
            }
            return transferred;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:81,代码来源:MyGridConveyorSystem.cs


示例18: RemoveConveyorBlock

        public void RemoveConveyorBlock(IMyConveyorEndpointBlock block)
        {
            // Invalidate iterator and remove block
            m_endpointIterator = null;
            m_conveyorEndpointBlocks.Remove(block);

            if (block is MyShipConnector)
                m_connectors.Remove(block as MyShipConnector);

            if (IsClosing) return;

            if (OnBeforeRemoveEndpointBlock != null)
                OnBeforeRemoveEndpointBlock(block);

            for (int i = 0; i < block.ConveyorEndpoint.GetLineCount(); ++i)
            {
                MyConveyorLine line = block.ConveyorEndpoint.GetConveyorLine(i);
                line.DisconnectEndpoint(block.ConveyorEndpoint);

                if (line.IsDegenerate)
                    m_lines.Remove(line);
            }
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:23,代码来源:MyGridConveyorSystem.cs


示例19: ConveyorSystemItemAmount

        public static MyFixedPoint ConveyorSystemItemAmount(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyDefinitionId itemId)
        {
            MyFixedPoint amount = 0;
            using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
            {
                lock (Pathfinding)
                {
                    SetTraversalPlayerId(playerId);
                    SetTraversalInventoryItemDefinitionId(itemId);

                    PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null);
                    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;

                            amount += inventory.GetItemAmount(itemId);
                        }
                    }
                }
            }
            return amount;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:34,代码来源:MyGridConveyorSystem.cs


示例20: TryMergeEndpointEndpoint

        private bool TryMergeEndpointEndpoint(IMyConveyorEndpointBlock endpointBlock1, IMyConveyorEndpointBlock endpointBlock2, ConveyorLinePosition pos1, ConveyorLinePosition pos2)
        {
            MyConveyorLine line1 = endpointBlock1.ConveyorEndpoint.GetConveyorLine(pos1);
            if (line1 == null)
                return false;

            MyConveyorLine line2 = endpointBlock2.ConveyorEndpoint.GetConveyorLine(pos2);
            if (line2 == null)
                return false;

            if (line1.Type != line2.Type)
                return false;

            if (line1.GetEndpoint(1) == null)
                line1.Reverse();
            Debug.Assert(line1.GetEndpoint(1) != null);
            if (line2.GetEndpoint(0) == null)
                line2.Reverse();
            Debug.Assert(line2.GetEndpoint(0) != null);

            line2.Merge(line1);
            endpointBlock1.ConveyorEndpoint.SetConveyorLine(pos1, line2);
            line1.RecalculateConductivity();
            line2.RecalculateConductivity();

            return true;
        }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:27,代码来源:MyGridConveyorSystem.cs



注:本文中的IMyConveyorEndpointBlock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IMyCubeBlock类代码示例发布时间:2022-05-24
下一篇:
C# IMyControllableEntity类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap