private HashSet <HeightMapNode> GetNonDiagonalNeighbours(HeightMapNode node) { return(new HashSet <HeightMapNode> (new[] { GetNode(node.GetX() + 1, node.GetY()), GetNode(node.GetX() - 1, node.GetY()), GetNode(node.GetX(), node.GetY() + 1), GetNode(node.GetX(), node.GetY() - 1), }.Where(pos => InBounds(pos.GetX(), pos.GetY())) )); }
private Vector3 HeightmapNodeToWorldSpace(HeightMapNode node) { var terrainData = _terrain.terrainData; var terrainSize = terrainData.size; var heightmapResolution = terrainData.heightmapResolution; return(new Vector3( node.GetX() * terrainSize.x / heightmapResolution, node.height * terrainSize.y, node.GetY() * terrainSize.z / heightmapResolution )); }
private List <Vector3> JoinShore(HeightMapNode lastSeen, HeightMapNode current, HeightMapNode target, HashSet <HeightMapNode> shorelineCandidates, HashSet <HeightMapNode> visited) { var allNeighbours = new HashSet <HeightMapNode>(GetNeighbours(current).Intersect(shorelineCandidates)); var unvisitedNeighbours = new HashSet <HeightMapNode>(allNeighbours.Except(visited)); if (allNeighbours.Contains(target) && visited.Count > 2) { return(new List <Vector3>()); } visited.Add(current); List <HeightMapNode> sortedNeighbours = SortNeighbours(unvisitedNeighbours, lastSeen, current); foreach (var neighbour in sortedNeighbours) { var shore = JoinShore(current, neighbour, target, shorelineCandidates, visited); if (shore != null) { shore.Add(HeightmapNodeToWorldSpace(neighbour)); return(shore); } } return(null); }
static DisplayableElement ToDisplayableElement(IPosition source, Color?forceColor) { Color?color = null; Image image = null; if (forceColor != null) { color = forceColor; } else if (source is Room) { color = Color.Red; } else if (source is Person) { color = Color.Blue; } else if (source is HeightMapNode) { HeightMapNode source_ = source as HeightMapNode; color = Color.Red; if (source_.ContactCount < HeightMapNode.MaxCountatCount * 0.25) { color = Color.Green; } else if (source_.ContactCount < HeightMapNode.MaxCountatCount * 0.50) { color = Color.Yellow; } else if (source_.ContactCount < HeightMapNode.MaxCountatCount * 0.75) { color = Color.Orange; } } else { switch (((Node)source).walkingDirection) { case WalkingDirection.ALL: color = Color.White; break; case WalkingDirection.NONE: color = Color.Black; break; case WalkingDirection.LEFT: image = Image.FromFile("../../../Assets/left_16.png"); break; case WalkingDirection.RIGHT: image = Image.FromFile("../../../Assets/right_16.png"); break; case WalkingDirection.UP: image = Image.FromFile("../../../Assets/up_16.png"); break; case WalkingDirection.DOWN: image = Image.FromFile("../../../Assets/down_16.png"); break; } } if (image != null) { return(new DisplayableElement(source.Position, image)); } else { return(new DisplayableElement(source.Position, (Color)color)); } }
private List <HeightMapNode> SortNeighbours(HashSet <HeightMapNode> neighbours, HeightMapNode last, HeightMapNode current) { return(neighbours .OrderBy(n => Mathf.Abs(Vector2Int.Distance(current.coords, n.coords))) .ToList()); }
private bool IsWaterCloseToLand(HeightMapNode node, HashSet <HeightMapNode> neighbours) { return(IsBelowSeaLevel(node) && neighbours.Any(IsAboveSeaLevel)); }
private bool IsAboveSeaLevel(HeightMapNode node) { return(node.height > _heightmapSeaLevel); }
private bool IsBelowSeaLevel(HeightMapNode node) { return(!IsAboveSeaLevel(node)); }
private bool IsNeighbour(HeightMapNode a, HeightMapNode b) { return(Mathf.Abs(a.GetX() - b.GetX()) <= 1 && Mathf.Abs(a.GetY() - b.GetY()) <= 1); //X and Y are always positive }