Пример #1
0
        void FloodFill(IntVector StartLocation, int IslandId, HashSet <IntVector> Visited, List <FloorIslandNode> IslandNodes, FloorChunkDB ChunkDB)
        {
            FloorChunk PreferedChunk = ChunkDB.GetChunkAt(StartLocation);

            if (!PreferedChunk.bConnectDoors)
            {
                // We don't want doors here
                return;
            }
            if (PreferedChunk == null)
            {
                return;
            }

            Queue <IntVector> Queue = new Queue <IntVector>();

            Queue.Enqueue(StartLocation);

            while (Queue.Count > 0)
            {
                IntVector Location = Queue.Dequeue();

                FloorChunk CurrentChunk = ChunkDB.GetChunkAt(Location);
                if (CurrentChunk != PreferedChunk)
                {
                    continue;
                }

                // Create a node here
                FloorIslandNode Node = new FloorIslandNode();
                Node.IslandId = IslandId;
                Node.Chunk    = CurrentChunk;
                Node.Location = Location;

                IslandNodes.Add(Node);

                // Add the neighbors to the queue
                List <IntVector> Neighbors = new List <IntVector>();
                Neighbors.Add(Location + new IntVector(-1, 0, 0));
                Neighbors.Add(Location + new IntVector(1, 0, 0));
                Neighbors.Add(Location + new IntVector(0, 0, 1));
                Neighbors.Add(Location + new IntVector(0, 0, -1));

                foreach (IntVector Neighbor in Neighbors)
                {
                    if (Visited.Contains(Neighbor))
                    {
                        continue;
                    }
                    FloorChunk NeighborChunk = ChunkDB.GetChunkAt(Neighbor);
                    if (NeighborChunk != null && NeighborChunk.Id == CurrentChunk.Id)
                    {
                        Queue.Enqueue(Neighbor);
                        Visited.Add(Neighbor);
                    }
                }
            }
        }