示例#1
0
        void DrawJump(Graphics gfx, JumpGateLink jump)
        {
            StarSystem a = galaxyGenerator.GetStarSystem(jump.start), b = galaxyGenerator.GetStarSystem(jump.end);

            if (a != null && b != null)
            {
                if (a.id.cellX != b.id.cellX && a.id.cellY != b.id.cellY)
                {
                    throw new Exception();
                }

                if (a.x < 0 || a.y < 0 || a.x > 1 || a.y > 1)
                {
                    throw new Exception();
                }
                if (b.x < 0 || b.y < 0 || b.x > 1 || b.y > 1)
                {
                    throw new Exception();
                }

                float x1 = (((int)a.id.cellX * cellSize) - scrollX) + (a.x * cellSize);
                float y1 = (((int)a.id.cellY * cellSize) - scrollY) + (a.y * cellSize);
                float x2 = (((int)b.id.cellX * cellSize) - scrollX) + (b.x * cellSize);
                float y2 = (((int)b.id.cellY * cellSize) - scrollY) + (b.y * cellSize);

                if (Math.Abs(x1 - x2) > cellSize * 2)
                {
                    throw new Exception();
                }
                if (Math.Abs(y1 - y2) > cellSize * 2)
                {
                    throw new Exception();
                }

                if (jump.didIntersect)
                {
                    gfx.DrawLine(new Pen(Brushes.Red), x1, y1, x2, y2);
                }
                else if (Math.Abs((int)a.id.cellX - (int)b.id.cellX) + Math.Abs((int)a.id.cellY - (int)b.id.cellY) != 1)
                {
                    gfx.DrawLine(new Pen(Brushes.Green), x1, y1, x2, y2);
                }
                else
                {
                    gfx.DrawLine(new Pen(Brushes.DarkOliveGreen), x1, y1, x2, y2);
                }
            }
        }
示例#2
0
        void CheckConnections(HashSet <StarSystemId> connectedSystems, StarSystemId checkSystem)
        {
            connectedSystems.Add(checkSystem);

            for (int n = 0; n < jumpGates.Count; n++)
            {
                JumpGateLink link = jumpGates[n];
                if (link.start.cellX == cellX && link.start.cellY == cellY &&
                    link.end.cellX == cellX && link.end.cellY == cellY)
                {
                    if (link.start == checkSystem && !connectedSystems.Contains(link.end))
                    {
                        CheckConnections(connectedSystems, link.end);
                    }
                    else if (link.end == checkSystem && !connectedSystems.Contains(link.start))
                    {
                        CheckConnections(connectedSystems, link.start);
                    }
                }
            }
        }
示例#3
0
        bool TryAddJumpGate(StarSystemId a, StarSystemId b, bool avoidIntersections)
        {
            if (a == b)
            {
                return(false);
            }

            // Check duplicates
            for (int n = 0; n < jumpGates.Count; n++)
            {
                if ((jumpGates[n].start == a && jumpGates[n].end == b) ||
                    (jumpGates[n].start == b && jumpGates[n].end == a))
                {
                    return(false);
                }
            }

            bool intersected = false;

//            if (avoidIntersections)
            {
                float checkStartX, checkStartY;
                float checkEndX, checkEndY;

                GetStarSystem(a).GetRelativePosition(this, out checkStartX, out checkStartY);
                GetStarSystem(b).GetRelativePosition(this, out checkEndX, out checkEndY);

                for (int n = 0; n < jumpGates.Count; n++)
                {
                    if (jumpGates[n].start != a && jumpGates[n].start != b &&
                        jumpGates[n].end != a && jumpGates[n].end != b)
                    {
                        float startX, startY;
                        float endX, endY;
                        GetStarSystem(jumpGates[n].start).GetRelativePosition(this, out startX, out startY);
                        GetStarSystem(jumpGates[n].end).GetRelativePosition(this, out endX, out endY);

                        if (DoIntersect(startX, startY, endX, endY, checkStartX, checkStartY, checkEndX, checkEndY))
                        {
                            if (avoidIntersections)
                            {
                                return(false);
                            }
                            else
                            {
                                intersected = true;
                            }
                        }
                    }
                }
            }

//            int connectionCount = GetConnectionCount();

            JumpGateLink newLink = new JumpGateLink(a, b);

            newLink.didIntersect = intersected;

            jumpGates.Add(newLink);

            //if(GetConnectionCount() == connectionCount)
            //{
            //    jumpGates.RemoveAt(jumpGates.Count - 1);
            //}

            return(true);
        }