public void Init(MyDefinitionId typeId, IMyConveyorEndpointBlock block) { FirstEndpoint = block.ConveyorEndpoint; ClearData(); Add(typeId, block); }
public static void PrepareTraversal( IMyConveyorEndpoint startingVertex, Predicate <IMyConveyorEndpoint> vertexFilter = null, Predicate <IMyConveyorEndpoint> vertexTraversable = null, Predicate <IMyPathEdge <IMyConveyorEndpoint> > edgeTraversable = null) { m_startingEndpoint = startingVertex; m_pathfinding.PrepareTraversal(startingVertex, vertexFilter, vertexTraversable, edgeTraversable); }
private static bool EdgeRules(IMyConveyorEndpoint edge) { if (edge.CubeBlock.OwnerId == 0) { return(true); } return(m_assemblerForPathfinding.FriendlyWithBlock(edge.CubeBlock)); }
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); }
public MyPhysicalDistributionGroup(MyDefinitionId typeId, MyResourceSourceComponent tempConnectedSource) { 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(); InitFromTempConnected(typeId, tempConnectedSource); }
public static void ReachablePostfix(IMyConveyorEndpoint from, IMyConveyorEndpoint to, ref bool __result) { if (!(from is MyMultilineConveyorEndpoint ep)) { return; } if (!Conveyors.TryGetValue(ep.CubeBlock.CubeGrid.GridSystems.ConveyorSystem, out var companion)) { return; } if (__result) { companion.Reachables.Add(new Tuple <IMyConveyorEndpoint, IMyConveyorEndpoint>(from, to)); } }
public static void AppendReachableEndpoints(IMyConveyorEndpoint source, long playerId, List <IMyConveyorEndpoint> reachable, MyPhysicalInventoryItem item, Predicate <IMyConveyorEndpoint> endpointFilter = null) { IMyConveyorEndpointBlock block = source.CubeBlock as IMyConveyorEndpointBlock; Debug.Assert(block != null); if (block == null) { return; } SetTraversalPlayerId(playerId); var itemId = item.Content.GetId(); SetTraversalInventoryItemDefinitionId(itemId); m_pathfinding.FindReachable(block.ConveyorEndpoint, reachable, endpointFilter, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null); }
public static bool ReachablePrefix(IMyConveyorEndpoint from, IMyConveyorEndpoint to, ref bool __result) { if (!(from is MyMultilineConveyorEndpoint ep)) { return(true); } if (!Conveyors.TryGetValue(ep.CubeBlock.CubeGrid.GridSystems.ConveyorSystem, out var companion)) { return(true); } var k = new Tuple <IMyConveyorEndpoint, IMyConveyorEndpoint>(from, to); if (!companion.Reachables.Contains(k)) { return(true); } __result = true; return(false); }
private static bool IsAccessAllowed(IMyConveyorEndpoint endpoint) { var relation = endpoint.CubeBlock.GetUserRelationToOwner(m_playerIdForAccessiblePredicate); var isEnemy = relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies; if (isEnemy) { return(false); } var conveyorSorter = endpoint.CubeBlock as MyConveyorSorter; if (conveyorSorter != null) { if (m_inventoryItemDefinitionId != new MyDefinitionId()) { return(conveyorSorter.IsAllowed(m_inventoryItemDefinitionId)); } } return(true); }
public static void FindReachable(IMyConveyorEndpoint from, List<IMyConveyorEndpoint> reachableVertices, Predicate<IMyConveyorEndpoint> vertexFilter = null, Predicate<IMyConveyorEndpoint> vertexTraversable = null, Predicate<IMyPathEdge<IMyConveyorEndpoint>> edgeTraversable = null) { lock (Pathfinding) { Pathfinding.FindReachable(from, reachableVertices, vertexFilter, vertexTraversable, edgeTraversable); } }
private bool EndpointPredicate(IMyConveyorEndpoint endpoint) { return endpoint.CubeBlock is IMyInventoryOwner || endpoint.CubeBlock == m_interactedEndpointBlock; }
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); } }
private void AllocateData() { FirstEndpoint = null; SinksByPriority = new HashSet<MyResourceSinkComponent>[m_sinkGroupPrioritiesTotal]; SourcesByPriority = new HashSet<MyResourceSourceComponent>[m_sourceGroupPrioritiesTotal]; SinkSourcePairs = new List<MyTuple<MyResourceSinkComponent, MyResourceSourceComponent>>(); SinkDataByPriority = new MySinkGroupData[m_sinkGroupPrioritiesTotal]; SourceDataByPriority = new MySourceGroupData[m_sourceGroupPrioritiesTotal]; StockpilingStorage = new List<int>(); OtherStorage = new List<int>(); for (int priorityIndex = 0; priorityIndex < m_sinkGroupPrioritiesTotal; ++priorityIndex) SinksByPriority[priorityIndex] = new HashSet<MyResourceSinkComponent>(); for (int priorityIndex = 0; priorityIndex < m_sourceGroupPrioritiesTotal; ++priorityIndex) SourcesByPriority[priorityIndex] = new HashSet<MyResourceSourceComponent>(); }
public void Dispose() { m_enumerated = null; m_line = null; }
public void InitializeConveyorEndpoint() { m_multilineConveyorEndpoint = new MyMultilineConveyorEndpoint(this); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_multilineConveyorEndpoint)); }
private bool EndpointPredicate(IMyConveyorEndpoint endpoint) { return (endpoint.CubeBlock != null && endpoint.CubeBlock.HasInventory) || endpoint.CubeBlock == m_interactedEndpointBlock; }
private static bool VertexRules(IMyConveyorEndpoint vertex) { return vertex.CubeBlock is MyAssembler && vertex.CubeBlock != m_assemblerForPathfinding; }
public OxygenProductionGroup(IMyOxygenBlock block) { var consumer = block as IMyOxygenConsumer; var producer = block as IMyOxygenProducer; var tank = block as MyOxygenTank; Producers = null; Consumers = null; FirstEndpoint = null; Consumers = new SortedDictionary<int, List<IMyOxygenConsumer>>(); if (consumer != null) { var newConsumerList = new List<IMyOxygenConsumer>(); newConsumerList.Add(consumer); Consumers.Add(consumer.GetPriority(), newConsumerList); FirstEndpoint = consumer.ConveyorEndpoint; } Producers = new SortedDictionary<int, List<IMyOxygenProducer>>(); if (producer != null) { var newProducerList = new List<IMyOxygenProducer>(); newProducerList.Add(producer); Producers.Add(producer.GetPriority(), newProducerList); FirstEndpoint = producer.ConveyorEndpoint; } Tanks = new List<MyOxygenTank>(); NonStockpilingTanks = new List<MyOxygenTank>(); if (tank != null) { Tanks.Add(tank); if (!tank.IsStockpiling) { NonStockpilingTanks.Add(tank); } FirstEndpoint = tank.ConveyorEndpoint; } }
public void InitFromTempConnected(MyDefinitionId typeId, MyResourceSinkComponent tempConnectedSink) { var conveyorEndPointBlock = tempConnectedSink.TemporaryConnectedEntity as IMyConveyorEndpointBlock; if(conveyorEndPointBlock != null) FirstEndpoint = conveyorEndPointBlock.ConveyorEndpoint; ClearData(); AddTempConnected(typeId, tempConnectedSink); }
public MyDebugRenderComponentDrawConveyorEndpoint(IMyConveyorEndpoint endpoint) : base(null) { ConveyorEndpoint = endpoint; }
public ConveyorLineEnumerator(IMyConveyorEndpoint enumerated) { index = -1; m_enumerated = enumerated; m_line = null; }
public static void DebugDraw(this IMyConveyorEndpoint endpoint) { if (!MyDebugDrawSettings.DEBUG_DRAW_CONVEYORS) { return; } Vector3 centerPos = new Vector3(); for (int i = 0; i < endpoint.GetLineCount(); ++i) { var position = endpoint.GetPosition(i); Vector3 pos = new Vector3(position.LocalGridPosition) + 0.5f * new Vector3(position.VectorDirection); centerPos += pos; } centerPos = centerPos * endpoint.CubeBlock.CubeGrid.GridSize / (float)endpoint.GetLineCount(); centerPos = Vector3.Transform(centerPos, endpoint.CubeBlock.CubeGrid.WorldMatrix); for (int i = 0; i < endpoint.GetLineCount(); ++i) { var position = endpoint.GetPosition(i); MyConveyorLine line = endpoint.GetConveyorLine(i); Vector3 pos = (new Vector3(position.LocalGridPosition) + 0.5f * new Vector3(position.VectorDirection)) * endpoint.CubeBlock.CubeGrid.GridSize; Vector3 pos2 = (new Vector3(position.LocalGridPosition) + 0.4f * new Vector3(position.VectorDirection)) * endpoint.CubeBlock.CubeGrid.GridSize; pos = Vector3.Transform(pos, endpoint.CubeBlock.CubeGrid.WorldMatrix); pos2 = Vector3.Transform(pos2, endpoint.CubeBlock.CubeGrid.WorldMatrix); Vector3 dir = Vector3.TransformNormal(position.VectorDirection * endpoint.CubeBlock.CubeGrid.GridSize * 0.5f, endpoint.CubeBlock.CubeGrid.WorldMatrix); Color color = line.IsFunctional ? Color.Orange : Color.DarkRed; color = line.IsWorking ? Color.GreenYellow : color; EndpointDebugShape shape = EndpointDebugShape.SHAPE_SPHERE; float dirMultiplier = 1.0f; float radius = 0.05f; if (line.GetEndpoint(0) == null || line.GetEndpoint(1) == null) { if (line.Type == Common.ObjectBuilders.MyObjectBuilder_ConveyorLine.LineType.SMALL_LINE) { dirMultiplier = 0.2f; radius = 0.015f; shape = EndpointDebugShape.SHAPE_SPHERE; } else { dirMultiplier = 0.1f; radius = 0.015f; shape = EndpointDebugShape.SHAPE_CAPSULE; } } else { if (line.Type == Common.ObjectBuilders.MyObjectBuilder_ConveyorLine.LineType.SMALL_LINE) { dirMultiplier = 1.0f; radius = 0.05f; shape = EndpointDebugShape.SHAPE_SPHERE; } else { dirMultiplier = 0.2f; radius = 0.05f; shape = EndpointDebugShape.SHAPE_CAPSULE; } } MyRenderProxy.DebugDrawLine3D(pos, pos + dir * dirMultiplier, color, color, true); if (shape == EndpointDebugShape.SHAPE_SPHERE) { MyRenderProxy.DebugDrawSphere(pos, radius * endpoint.CubeBlock.CubeGrid.GridSize, color.ToVector3(), 1.0f, false); } else if (shape == EndpointDebugShape.SHAPE_CAPSULE) { MyRenderProxy.DebugDrawCapsule(pos - dir * dirMultiplier, pos + dir * dirMultiplier, radius * endpoint.CubeBlock.CubeGrid.GridSize, color, false); } if (MyDebugDrawSettings.DEBUG_DRAW_CONVEYORS_LINE_IDS) { MyRenderProxy.DebugDrawText3D(pos2, line.GetHashCode().ToString(), color, 0.6f, false); } MyRenderProxy.DebugDrawLine3D(pos, centerPos, color, color, false); } }
public static bool Reachable(IMyConveyorEndpoint from, IMyConveyorEndpoint to) { bool isReachable = false; lock (Pathfinding) { isReachable = Pathfinding.Reachable(from, to); } return isReachable; }
private static bool VertexRules(IMyConveyorEndpoint vertex) { return(vertex.CubeBlock is MyAssembler && vertex.CubeBlock != m_assemblerForPathfinding); }
private static bool IsAccessAllowed(IMyConveyorEndpoint endpoint) { var relation = endpoint.CubeBlock.GetUserRelationToOwner(m_playerIdForAccessiblePredicate); var isEnemy = relation == VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies; if (isEnemy) { return false; } var conveyorSorter = endpoint.CubeBlock as MyConveyorSorter; if (conveyorSorter != null) { if (m_inventoryItemDefinitionId != new MyDefinitionId()) return conveyorSorter.IsAllowed(m_inventoryItemDefinitionId); } return true; }
public static void AppendReachableEndpoints(IMyConveyorEndpoint source, long playerId, List<IMyConveyorEndpoint> reachable, MyPhysicalInventoryItem item, Predicate<IMyConveyorEndpoint> endpointFilter = null) { IMyConveyorEndpointBlock block = source.CubeBlock as IMyConveyorEndpointBlock; Debug.Assert(block != null); if (block == null) return; lock (Pathfinding) { SetTraversalPlayerId(playerId); var itemId = item.Content.GetId(); SetTraversalInventoryItemDefinitionId(itemId); Pathfinding.FindReachable(block.ConveyorEndpoint, reachable, endpointFilter, IsAccessAllowedPredicate, NeedsLargeTube(itemId) ? IsConveyorLargePredicate : null); } }
private static bool EdgeRules(IMyConveyorEndpoint edge) { return m_assemblerForPathfinding.FriendlyWithBlock(edge.CubeBlock); }
public static void PrepareTraversal( IMyConveyorEndpoint startingVertex, Predicate<IMyConveyorEndpoint> vertexFilter = null, Predicate<IMyConveyorEndpoint> vertexTraversable = null, Predicate<IMyPathEdge<IMyConveyorEndpoint>> edgeTraversable = null) { m_startingEndpoint = startingVertex; lock (Pathfinding) { Pathfinding.PrepareTraversal(startingVertex, vertexFilter, vertexTraversable, edgeTraversable); } }