public void Init(MyCubeBlock myBlock, ConveyorLinePosition a, ConveyorLinePosition b, MyObjectBuilder_ConveyorLine.LineType type, MyObjectBuilder_ConveyorLine.LineConductivity conductivity = MyObjectBuilder_ConveyorLine.LineConductivity.FULL)
        {
            CubeBlock           = myBlock;
            ConnectingPosition1 = a;
            ConnectingPosition2 = b;

            // Neighbour grid position of one of the connecting positions is inside this block
            var linePosition = (myBlock as IMyConveyorSegmentBlock).ConveyorSegment.ConnectingPosition1.NeighbourGridPosition;

            ConveyorLine = myBlock.CubeGrid.GridSystems.ConveyorSystem.GetDeserializingLine(linePosition);
            if (ConveyorLine == null)
            {
                ConveyorLine = new MyConveyorLine();
                if (IsCorner)
                {
                    ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, CalculateCornerPosition());
                }
                else
                {
                    ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, (Vector3I?)null);
                }
            }
            else
            {
                Debug.Assert(ConveyorLine.Type == type, "Conveyor line type mismatch on segment deserialization");
            }

            myBlock.SlimBlock.ComponentStack.IsFunctionalChanged += CubeBlock_IsFunctionalChanged;
        }
        public void Init(MyCubeBlock myBlock, ConveyorLinePosition a, ConveyorLinePosition b, MyObjectBuilder_ConveyorLine.LineType type, MyObjectBuilder_ConveyorLine.LineConductivity conductivity = MyObjectBuilder_ConveyorLine.LineConductivity.FULL)
        {
            CubeBlock = myBlock;
            ConnectingPosition1 = a;
            ConnectingPosition2 = b;

            // Neighbour grid position of one of the connecting positions is inside this block
            var linePosition = (myBlock as IMyConveyorSegmentBlock).ConveyorSegment.ConnectingPosition1.NeighbourGridPosition;

            ConveyorLine = myBlock.CubeGrid.GridSystems.ConveyorSystem.GetDeserializingLine(linePosition);
            if (ConveyorLine == null)
            {
                ConveyorLine = new MyConveyorLine();
                if (IsCorner)
                    ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, CalculateCornerPosition());
                else
                    ConveyorLine.Init(a, b, myBlock.CubeGrid, type, conductivity, (Vector3I?)null);
            }
            else
            {
                Debug.Assert(ConveyorLine.Type == type, "Conveyor line type mismatch on segment deserialization");
            }

            myBlock.SlimBlock.ComponentStack.IsFunctionalChanged += CubeBlock_IsFunctionalChanged;
        }
        public void BeforeBlockDeserialization(List <MyObjectBuilder_ConveyorLine> lines)
        {
            ProfilerShort.Begin("ConveyorSystem.BeforeBlockDeserialization()");
            if (lines == null)
            {
                ProfilerShort.End();
                return;
            }

            m_lineEndpoints     = new Dictionary <ConveyorLinePosition, MyConveyorLine>(lines.Count * 2);
            m_linePoints        = new Dictionary <Vector3I, MyConveyorLine>(lines.Count * 4);
            m_deserializedLines = new HashSet <MyConveyorLine>();

            foreach (var lineBuilder in lines)
            {
                MyConveyorLine line = new MyConveyorLine();
                line.Init(lineBuilder, m_grid);
                if (!line.CheckSectionConsistency())
                {
                    continue;
                }

                ConveyorLinePosition start = new ConveyorLinePosition(lineBuilder.StartPosition, lineBuilder.StartDirection);
                ConveyorLinePosition end   = new ConveyorLinePosition(lineBuilder.EndPosition, lineBuilder.EndDirection);

                try
                {
                    m_lineEndpoints.Add(start, line);
                    m_lineEndpoints.Add(end, line);

                    foreach (var position in line)
                    {
                        m_linePoints.Add(position, line);
                    }

                    m_deserializedLines.Add(line);
                    m_lines.Add(line);
                }
                catch (ArgumentException)
                {
                    // Something was wrong in the conveyor line serialization. Display an assert, but don't crash.
                    Debug.Assert(false, "Problem with deserializing lines. Recalculating all lines from scratch...");
                    // Reset the deserialization structures and rebuild the conveyor lines anew
                    m_lineEndpoints     = null;
                    m_deserializedLines = null;
                    m_linePoints        = null;
                    m_lines.Clear();
                    break;
                }
            }
            ProfilerShort.End();
        }
Exemplo n.º 4
0
        public MyMultilineConveyorEndpoint(MyCubeBlock myBlock)
        {
            ProfilerShort.Begin("MyMultilineConveyorEndpoint(...)");
            m_block = myBlock;

            MyConveyorLine.BlockLinePositionInformation[] positionInfo = MyConveyorLine.GetBlockLinePositions(myBlock);
            m_conveyorLines = new MyConveyorLine[positionInfo.Length];

            MyGridConveyorSystem conveyorSystem = myBlock.CubeGrid.GridSystems.ConveyorSystem;

            int i = 0;

            foreach (var position in positionInfo)
            {
                var gridPosition = PositionToGridCoords(position.Position);

                MyConveyorLine line = conveyorSystem.GetDeserializingLine(gridPosition);
                if (line == null)
                {
                    line = new MyConveyorLine();
                    line.Init(gridPosition, gridPosition.GetConnectingPosition(), myBlock.CubeGrid, position.LineType, position.LineConductivity);
                    line.InitEndpoints(this, null);
                }
                else
                {
                    if (line.GetEndpointPosition(0).Equals(gridPosition))
                    {
                        line.SetEndpoint(0, this);
                    }
                    else if (line.GetEndpointPosition(1).Equals(gridPosition))
                    {
                        line.SetEndpoint(1, this);
                    }
                }
                m_conveyorLines[i] = line;
                i++;
            }

            myBlock.SlimBlock.ComponentStack.IsFunctionalChanged += UpdateLineFunctionality;
            myBlock.CubeGrid.GridSystems.ConveyorSystem.ResourceSink.IsPoweredChanged += UpdateLineFunctionality;

            m_pathfindingData = new MyPathfindingData(this);
            ProfilerShort.End();
        }
Exemplo n.º 5
0
        public void BeforeBlockDeserialization(List<MyObjectBuilder_ConveyorLine> lines)
        {
            ProfilerShort.Begin("ConveyorSystem.BeforeBlockDeserialization()");
            if (lines == null)
            {
                ProfilerShort.End();
                return;
            }

            m_lineEndpoints = new Dictionary<ConveyorLinePosition, MyConveyorLine>(lines.Count * 2);
            m_linePoints = new Dictionary<Vector3I, MyConveyorLine>(lines.Count * 4);
            m_deserializedLines = new HashSet<MyConveyorLine>();

            foreach (var lineBuilder in lines)
            {
                MyConveyorLine line = new MyConveyorLine();
                line.Init(lineBuilder, m_grid);
                if (!line.CheckSectionConsistency()) continue;

                ConveyorLinePosition start = new ConveyorLinePosition(lineBuilder.StartPosition, lineBuilder.StartDirection);
                ConveyorLinePosition end = new ConveyorLinePosition(lineBuilder.EndPosition, lineBuilder.EndDirection);

                try
                {
                    m_lineEndpoints.Add(start, line);
                    m_lineEndpoints.Add(end, line);

                    foreach (var position in line)
                    {
                        m_linePoints.Add(position, line);
                    }

                    m_deserializedLines.Add(line);
                    m_lines.Add(line);
                }
                catch (ArgumentException)
                {
                    // Something was wrong in the conveyor line serialization. Display an assert, but don't crash.
                    Debug.Assert(false, "Problem with deserializing lines. Recalculating all lines from scratch...");
                    // Reset the deserialization structures and rebuild the conveyor lines anew
                    m_lineEndpoints = null;
                    m_deserializedLines = null;
                    m_linePoints = null;
                    m_lines.Clear();
                    break;
                }
            }
            ProfilerShort.End();
        }