public void Add(PathLink link) { PathLink existingLink = links.FirstOrDefault(x => x.destinationNode == link.destinationNode); if (existingLink == null) { links.Add(link); } else if (existingLink.TerrainType.cost > link.TerrainType.cost) { existingLink.update(link); } }
internal List <Point> createRoad(PathLink pathLink, TerrainType roadType) { var link2 = pathLink.reverseLink; var node1 = link2.destinationNode; var node2 = pathLink.destinationNode; node1.links.Remove(pathLink); node2.links.Remove(link2); var originNode = node1; var roadNodes = new List <PathNode>(); foreach (var destinationPoint in getIntermediatePoints(node1.position, node2.position)) { var destinationNode = new PathNode(destinationPoint); roadNodes.Add(destinationNode); createLink(originNode, destinationNode, roadType); originNode = destinationNode; } createLink(originNode, node2, roadType); //add links to rest of area nodes foreach (var areaNode in nodes) { if (areaNode == node1 || areaNode == node2) { continue; } foreach (var roadNode in roadNodes) { createLink(areaNode, roadNode, terrainType); } } //prune illegal paths var newIntersector = new RoadIntersector(node1.position, node2.position); roadIntersectors.Add(newIntersector); foreach (var node in nodes) { newIntersector.prune(node); } nodes.AddRange(roadNodes); var roadPoints = roadNodes.ConvertAll(x => x.position); roadPoints.Add(node2.position); return(roadPoints); }
private void createLink(PathNode pathNode1, PathNode pathNode2, TerrainType terrainType) { if (roadIntersectors.Any(x => x.intersects(pathNode1.position, pathNode2.position))) { return; } float length = (pathNode1.position - pathNode2.position).Length; PathLink link1 = new PathLink(pathNode2, terrainType, length, this); PathLink link2 = new PathLink(pathNode1, terrainType, length, this); link1.reverseLink = link2; link2.reverseLink = link1; pathNode1.Add(link1); pathNode2.Add(link2); }
internal void update(PathLink link) { pathArea = link.pathArea; _terrainType = link._terrainType; }