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);
        }
        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();
        }
示例#4
0
        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);
            }
        }