private void UpdateLineReferences(MyConveyorLine oldLine, MyConveyorLine newLine) { for (int i = 0; i < 2; ++i) { if (oldLine.GetEndpoint(i) != null) { oldLine.GetEndpoint(i).SetConveyorLine(oldLine.GetEndpointPosition(i), newLine); } } foreach (var position in oldLine) { var block = m_grid.GetCubeBlock(position); if (block == null) { continue; } var segmentBlock = block.FatBlock as IMyConveyorSegmentBlock; Debug.Assert(segmentBlock != null, "Conveyor line was going through a non-segment block"); if (segmentBlock == null) { continue; } segmentBlock.ConveyorSegment.SetConveyorLine(newLine); } oldLine.RecalculateConductivity(); newLine.RecalculateConductivity(); }
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); }
/// <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); }
private void UpdateLineReferences(MyConveyorLine oldLine, MyConveyorLine newLine) { for (int i = 0; i < 2; ++i) { if (oldLine.GetEndpoint(i) != null) { oldLine.GetEndpoint(i).SetConveyorLine(oldLine.GetEndpointPosition(i), newLine); } } foreach (var position in oldLine) { var block = m_grid.GetCubeBlock(position); if (block == null) continue; var segmentBlock = block.FatBlock as IMyConveyorSegmentBlock; Debug.Assert(segmentBlock != null, "Conveyor line was going through a non-segment block"); if (segmentBlock == null) continue; segmentBlock.ConveyorSegment.SetConveyorLine(newLine); } oldLine.RecalculateConductivity(); newLine.RecalculateConductivity(); }