本文整理汇总了C#中IMyConveyorEndpointBlock类的典型用法代码示例。如果您正苦于以下问题:C# IMyConveyorEndpointBlock类的具体用法?C# IMyConveyorEndpointBlock怎么用?C# IMyConveyorEndpointBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMyConveyorEndpointBlock类属于命名空间,在下文中一共展示了IMyConveyorEndpointBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(MyDefinitionId typeId, IMyConveyorEndpointBlock block)
{
FirstEndpoint = block.ConveyorEndpoint;
ClearData();
Add(typeId, block);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
}
}
}
}
示例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);
}
示例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();
}
示例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;
//.........这里部分代码省略.........