コード例 #1
0
        // splits given list of positions into groups. positions in one group are interconnected. positions in different groups are isolated.
        private List <HashSet <Vector3Int> > collectIsolatedPositions(List <Vector3Int> list)
        {
            List <HashSet <Vector3Int> > groups = new List <HashSet <Vector3Int> >();

            while (list.Count() > 0)
            {
                HashSet <Vector3Int> connectedPositions = new HashSet <Vector3Int>();
                Vector3Int           first = list.RemoveAndGet(0); // first position is connected to itself
                connectedPositions.Add(first);
                for (int i = list.Count() - 1; i >= 0; i--)
                {
                    Vector3Int pos = list[i];
                    // positions are accessible neighoburs or path exists
                    if (pos.isNeighbour(first) && passage.hasPathBetweenNeighbours(pos, first) || AStar.get().makeShortestPath(pos, first) != null)
                    {
                        connectedPositions.Add(list.RemoveAndGet(i));
                    }
                }
                groups.Add(connectedPositions);
            }
            return(groups);
        }
コード例 #2
0
        /**
         * Returns area numbers of areas accessible from given position.
         * Does not return unset areas (0).
         */
        private HashSet <byte> getNeighbours(int cx, int cy, int cz)
        {
            HashSet <byte> neighbours = new HashSet <byte>();

            if (passage.getPassage(cx, cy, cz) != PASSABLE.VALUE)
            {
                return(neighbours);                                                  // impassable sell cannot have neigbours
            }
            for (int x = cx - 1; x < cx + 2; x++)
            {
                for (int y = cy - 1; y < cy + 2; y++)
                {
                    for (int z = cz - 1; z < cz + 2; z++)
                    {
                        if (passage.hasPathBetweenNeighbours(x, y, z, cx, cy, cz))
                        {
                            neighbours.Add(passage.area.get(x, y, z));
                        }
                    }
                }
            }
            neighbours.Remove(0);
            return(neighbours);
        }
コード例 #3
0
 /**
  * Filters all tiles where walking creature cannot step into.
  * Clears all, if center tile is not passable.
  */
 public NeighbourPositionStream filterConnectedToCenter()
 {
     stream = stream.Where(position => passageMap.hasPathBetweenNeighbours(position, center));
     return(this);
 }