Example #1
0
        private void AddAdditionalRoadsLeadingOutOfMap()
        {
            int count = -1;

            while (roadsLeadingOutOfMap.Count < MinimumRoadsLeadingOutOfMap &&
                   roadsLeadingOutOfMap.Count != count)
            {
                count = roadsLeadingOutOfMap.Count;
                var pointsNextToBorder = from n in info.Roads.Nodes
                                         where n.CanBeConnected &&
                                         n.Neighbors.Count == 2 &&
                                         map.IsWithinMap(n.Position) //&&
                                                                     //!roadsLeadingOutOfMap.Select(r => r.Node2.Position)
                                                                     //                     .Any(p => (p - n.Position).VectorLengthSquared() < MinimumDistanceBetweenRoadsLeadingOutOfMap * MinimumDistanceBetweenRoadsLeadingOutOfMap)
                                         let x                 = System.Math.Min(n.Position.X, map.HeightMap.MapWidth * Map.TileWidth - n.Position.X)
                                                         let y = System.Math.Min(n.Position.Y, map.HeightMap.MapHeight * Map.TileWidth - n.Position.Y)
                                                                 orderby System.Math.Min(x, y)
                                                                 select new { X = x, Y = y, Node = n };

                foreach (var point in pointsNextToBorder)
                {
                    if (info.IsCancellationRequested)
                    {
                        return;
                    }

                    Point destination;
                    if (point.X < point.Y)
                    {
                        if (point.X < point.Node.Position.X)
                        {
                            destination = new Point((map.HeightMap.MapWidth + outOfMapDestinationDistance) * Map.TileWidth, point.Node.Position.Y);
                        }
                        else
                        {
                            destination = new Point(-outOfMapDestinationDistance * Map.TileWidth, point.Node.Position.Y);
                        }
                    }
                    else
                    {
                        if (point.Y < point.Node.Position.Y)
                        {
                            destination = new Point(point.Node.Position.X, (map.HeightMap.MapHeight + outOfMapDestinationDistance) * Map.TileWidth);
                        }
                        else
                        {
                            destination = new Point(point.Node.Position.X, -outOfMapDestinationDistance * Map.TileWidth);
                        }
                    }

                    var destinationNode = new RoadGraphNode(destination, false, false);
                    var edge            = new RoadGraphEdge(point.Node, destinationNode, (destination - point.Node.Position).VectorLength());
                    if (TryAddRoadLeadingOutOfMap(point.Node, destination))
                    {
                        break;
                    }
                }
            }
        }
Example #2
0
 public RoadGraphEdge FindJoiningIntersection(RoadGraphNode start, RoadGraphEdge target)
 {
     return(start.edges.Find(e =>
     {
         return roadGraph.GetNode(e.id, e.subId).edges.Exists(edge =>
         {
             return edge.id == target.id && edge.subId == target.subId;
         });
     }));
 }
Example #3
0
        private bool TryAddEdge(RoadGraphEdge edge, IEnumerable <Point> positions)
        {
            var tiles = tileGraph.GetTiles(map, positions);

            if (tiles != null) // path possible
            {
                info.Roads.AddRoad(positions, map, info.ObjectFactory, info.Settings.Scenery.Road);
                tileGraph.UpdateTiles(tiles, TileInfo.Road, 2);
                return(true);
            }

            return(false);
        }
Example #4
0
 public static bool Equals(RoadGraphEdge point1, RoadGraphEdge point2)
 {
     if (point1.StartPoint == point2.StartPoint && point1.EndPoint == point2.EndPoint)
     {
         return(true);
     }
     else if (point1.StartPoint == point2.EndPoint && point1.EndPoint == point2.StartPoint)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        private bool TryAddEdge(RoadGraphEdge edge)
        {
            //int count = edge.Length < 150 * 150 ? 5 : 8;
            int count = (int)System.Math.Max((edge.Length / 100) + 1, 3);

            ICurve curve = GetCurve(edge.Node1, edge.Node2);

            var positions = curve.GetPoints(count);

            if (!CanAddIncomingRoad(edge.Node1, positions.ElementAt(1)) || !CanAddIncomingRoad(edge.Node2, positions.ElementAt(count - 2)))
            {
                return(false);
            }

            return(TryAddEdge(edge, positions));
        }
Example #6
0
    public void RebuildRoadData()
    {
        Segments = new List <RoadGraphEdge>();
        List <GameObject> completedNodes = new List <GameObject>();

        // TODO: Make sure this algorithm isn't terribly slow
        foreach (GameObject node in nodes)
        {
            foreach (GameObject connection in node.GetComponent <RoadNode>().Connections)
            {
                RoadGraphEdge segment = new RoadGraphEdge(node, connection);
                if (!Segments.Contains(segment))
                {
                    Segments.Add(segment);
                    Debug.Log("Segment added");
                }
            }
        }
    }
Example #7
0
        private bool TryAddRoadLeadingOutOfMap(RoadGraphNode node, Point destination)
        {
            if (roadsLeadingOutOfMap.Any(r => (destination - r.Node2.Position).VectorLengthSquared() < MinimumDistanceBetweenRoadsLeadingOutOfMap * MinimumDistanceBetweenRoadsLeadingOutOfMap))
            {
                return(false);
            }

            var destinationNode = new RoadGraphNode(destination, false, false);
            var edge            = new RoadGraphEdge(node, destinationNode, (destination - node.Position).VectorLength());

            if (TryAddEdge(edge))
            {
                info.Roads.Nodes.AddLast(destinationNode);
                roadsLeadingOutOfMap.Add(edge);
                return(true);
            }

            return(false);
        }
Example #8
0
    public void RebuildRoadData()
    {
        Segments = new List<RoadGraphEdge>();
        List<GameObject> completedNodes = new List<GameObject>();

        // TODO: Make sure this algorithm isn't terribly slow
        foreach (GameObject node in nodes)
        {
            foreach (GameObject connection in node.GetComponent<RoadNode>().Connections)
            {
                RoadGraphEdge segment = new RoadGraphEdge(node, connection);
                if (!Segments.Contains(segment))
                {
                    Segments.Add(segment);
                    Debug.Log("Segment added");
                }
            }
        }
    }
Example #9
0
 public bool Equals(RoadGraphEdge roadSegment)
 {
     return(RoadGraphEdge.Equals(this, roadSegment));
 }