예제 #1
0
    private void CreateRoom(Vector3Int origin)
    {
        if (metaDataLayer.Get(origin).RoomNumber != -1)
        {
            return;
        }
        var roomPositions = new HashSet <Vector3Int>();
        var freePositions = new UniqueQueue <Vector3Int>();

        freePositions.Enqueue(origin);

        var isSpace = false;

        // breadth-first search of the connected tiles that are not occupied
        while (!freePositions.IsEmpty)
        {
            if (freePositions.TryDequeue(out Vector3Int position))
            {
                roomPositions.Add(position);

                Vector3Int[] neighbors = MetaUtils.GetNeighbors(position, null);
                for (var i = 0; i < neighbors.Length; i++)
                {
                    Vector3Int neighbor = neighbors[i];
                    if (metaTileMap.IsSpaceAt(neighbor, true))
                    {
                        Vector3Int worldPosition = MatrixManager.LocalToWorldInt(neighbor, MatrixManager.Get(matrix.Id));

                        // If matrix manager says, the neighboring positions is space, the whole room is connected to space.
                        // Otherwise there is another matrix, blocking off the connection to space.
                        if (MatrixManager.IsSpaceAt(worldPosition, true, matrix.MatrixInfo))
                        {
                            isSpace = true;
                        }
                    }
                    else if (metaTileMap.IsAtmosPassableAt(position, neighbor, true))
                    {
                        // if neighbor position is not yet a room in the meta data layer and not in the room positions list,
                        // add it to the positions that need be checked
                        if (!roomPositions.Contains(neighbor) && !metaDataLayer.IsRoomAt(neighbor))
                        {
                            freePositions.Enqueue(neighbor);
                        }
                    }
                }
            }
        }

        AssignType(roomPositions, isSpace ? NodeType.Space : NodeType.Room);

        SetupNeighbors(roomPositions);
    }
예제 #2
0
    private void SetupNeighbors(MetaDataNode node)
    {
        Vector3Int[] neighbors = MetaUtils.GetNeighbors(node.Position);

        for (int i = 0; i < neighbors.Length; i++)
        {
            if (metaTileMap.IsSpaceAt(neighbors[i]))
            {
                if (node.IsRoom)
                {
                    externalNodes.Add(node);
                }

                Vector3 worldPosition = transform.TransformPoint(neighbors[i] + Vector3Int.one);
                worldPosition.z = 0;

                if (!MatrixManager.IsSpaceAt(worldPosition.RoundToInt()))
                {
                    MatrixInfo matrixInfo = MatrixManager.AtPoint(worldPosition.RoundToInt());

                    if (matrixInfo.MetaTileMap != metaTileMap)
                    {
                        Vector3Int localPosition = MatrixManager.WorldToLocalInt(worldPosition, matrixInfo);

                        if (matrixInfo.MetaTileMap.IsAtmosPassableAt(localPosition))
                        {
                            node.AddNeighbor(matrixInfo.MetaDataLayer.Get(localPosition));
                        }

                        continue;
                    }
                }
            }

            if (metaTileMap.IsAtmosPassableAt(neighbors[i]))
            {
                MetaDataNode neighborNode = metaDataLayer.Get(neighbors[i]);

                if (metaTileMap.IsSpaceAt(neighbors[i]))
                {
                    neighborNode.Type = NodeType.Space;
                }

                node.AddNeighbor(neighborNode);
            }
        }
    }
예제 #3
0
 public void CalculateAttachedNodes()
 {
     for (int i = 0; i < allDirections.Length; i++)
     {
         var dir = allDirections[i];
         if (HasDirection(direction, dir))
         {
             var adjacentTurf = MetaUtils.GetNeighbors(registerTile.WorldPositionServer, DirectionToVector3IntList(dir));
             var pipe         = GetAnchoredPipe(adjacentTurf[0], OppositeDirection(dir));
             if (pipe)
             {
                 nodes.Add(pipe);
                 pipe.nodes.Add(this);
                 pipe.CalculateSprite();
             }
         }
     }
 }
예제 #4
0
    private void CreateRoom(Vector3Int origin)
    {
        var roomPositions = new HashSet <Vector3Int>();
        var freePositions = new UniqueQueue <Vector3Int>();

        freePositions.Enqueue(origin);

        var isSpace = false;

        while (!freePositions.IsEmpty)
        {
            Vector3Int position;
            if (freePositions.TryDequeue(out position))
            {
                roomPositions.Add(position);

                Vector3Int[] neighbors = MetaUtils.GetNeighbors(position);
                for (var i = 0; i < neighbors.Length; i++)
                {
                    Vector3Int neighbor = neighbors[i];
                    if (metaTileMap.IsSpaceAt(neighbor))
                    {
                        Vector3 worldPosition = transform.TransformPoint(neighbor + Vector3Int.one);
                        worldPosition.z = 0;
                        if (MatrixManager.IsSpaceAt(worldPosition.RoundToInt()))
                        {
                            isSpace = true;
                        }
                    }
                    else if (metaTileMap.IsAtmosPassableAt(neighbor))
                    {
                        if (!roomPositions.Contains(neighbor) && !metaDataLayer.IsRoomAt(neighbor))
                        {
                            freePositions.Enqueue(neighbor);
                        }
                    }
                }
            }
        }

        AssignType(roomPositions, isSpace ? NodeType.Space : NodeType.Room);

        SetupNeighbors(roomPositions);
    }
예제 #5
0
    public void CalculateAttachedNodes()
    {
        Vector3Int[] dir;
        if (direction == Direction.NORTH || direction == Direction.SOUTH)
        {
            dir = new Vector3Int[] { Vector3Int.up, Vector3Int.down };
        }
        else
        {
            dir = new Vector3Int[] { Vector3Int.left, Vector3Int.right };
        }
        var adjacentTurfs = MetaUtils.GetNeighbors(registerTile.WorldPositionServer, dir);

        for (int i = 0; i < adjacentTurfs.Length; i++)
        {
            var pipe = GetAnchoredPipe(adjacentTurfs[i]);
            if (pipe)
            {
                nodes.Add(pipe);
                pipe.nodes.Add(this);
                pipe.SpriteChange();
            }
        }
    }