Пример #1
0
    private void SetupNeighbors(MetaDataNode node)
    {
        Vector3 nodeWorldPosition = MatrixManager.LocalToWorldInt(node.Position, MatrixManager.Get(matrix.Id));

        // Look in every direction for neighboring tiles.
        foreach (Vector3Int dir in MetaUtils.Directions)
        {
            Vector3Int neighbor = dir + node.Position;

            if (metaTileMap.IsSpaceAt(neighbor, true))
            {
                // if current node is a room, but the neighboring is a space tile, this node needs to be checked regularly for changes by other matrices
                if (node.IsRoom && !externalNodes.ContainsKey(node))
                {
                    externalNodes[node] = node;
                }

                // If the node is not space, check other matrices if it has a tile next to this node.
                if (!node.IsSpace)
                {
                    Vector3 neighborWorldPosition = MatrixManager.LocalToWorldInt(neighbor, MatrixManager.Get(matrix.Id));

                    // if matrixManager says, it's not space at the neighboring position, there must be a matrix with a non-space tile
                    if (!MatrixManager.IsSpaceAt(neighborWorldPosition.RoundToInt(), true))
                    {
                        MatrixInfo matrixInfo = MatrixManager.AtPoint(neighborWorldPosition.RoundToInt(), true);

                        // ignore tilemap of current node
                        if (matrixInfo.MetaTileMap != metaTileMap)
                        {
                            // Check if atmos can pass to the neighboring position
                            Vector3Int neighborlocalPosition = MatrixManager.WorldToLocalInt(neighborWorldPosition, matrixInfo);
                            Vector3Int nodeLocalPosition     = MatrixManager.WorldToLocalInt(nodeWorldPosition, matrixInfo);

                            if (matrixInfo.MetaTileMap.IsAtmosPassableAt(nodeLocalPosition, neighborlocalPosition, true))
                            {
                                // add node of other matrix to the neighbors of the current node
                                node.AddNeighbor(matrixInfo.MetaDataLayer.Get(neighborlocalPosition), dir);
                            }

                            // skip other checks for neighboring tile on local tilemap, to prevent the space tile to be added as a neighbor
                            continue;
                        }
                    }
                }
            }

            // If neighboring tile on local tilemap is atmos passable, add it as a neighbor
            if (metaTileMap.IsAtmosPassableAt(node.Position, neighbor, true))
            {
                MetaDataNode neighborNode = metaDataLayer.Get(neighbor);

                if (metaTileMap.IsSpaceAt(neighbor, true))
                {
                    neighborNode.Type = NodeType.Space;
                }

                node.AddNeighbor(neighborNode, dir);
            }
        }
    }
Пример #2
0
    private void SetupNeighbors(MetaDataNode node)
    {
        // Look in every direction for neighboring tiles.
        foreach (Vector3Int dir in MetaUtils.Directions)
        {
            Vector3Int neighbor = dir + node.Position;

            if (metaTileMap.IsSpaceAt(neighbor, true))
            {
                // if current node is a room, but the neighboring is a space tile, this node needs to be checked regularly for changes by other matrices
                if (node.IsRoom && !externalNodes.ContainsKey(node) && metaTileMap.IsSpaceAt(node.Position, true) == false)
                {
                    externalNodes[node] = node;
                }

                // If the node is not space, check other matrices if it has a tile next to this node.
                if (!node.IsSpace)
                {
                    Vector3 neighborWorldPosition = MatrixManager.LocalToWorldInt(neighbor, MatrixManager.Get(matrix.Id));

                    // if matrixManager says, it's not space at the neighboring position, there must be a matrix with a non-space tile
                    if (!MatrixManager.IsSpaceAt(neighborWorldPosition.RoundToInt(), true, matrix.MatrixInfo))
                    {
                        MatrixInfo matrixInfo = MatrixManager.AtPoint(neighborWorldPosition.RoundToInt(), true);

                        // ignore tilemap of current node
                        if (matrixInfo != null && matrixInfo.MetaTileMap != metaTileMap)
                        {
                            // Check if atmos can pass to the neighboring position
                            Vector3Int neighborlocalPosition = MatrixManager.WorldToLocalInt(neighborWorldPosition, matrixInfo);

                            var OppositeNode = matrixInfo.MetaDataLayer.Get(neighborlocalPosition);

                            // add node of other matrix to the neighbors of the current node
                            node.AddNeighbor(OppositeNode, dir);

                            if (dir == Vector3Int.up)
                            {
                                OppositeNode.AddNeighbor(node, Vector3Int.down);
                            }
                            else if (dir == Vector3Int.down)
                            {
                                OppositeNode.AddNeighbor(node, Vector3Int.up);
                            }
                            else if (dir == Vector3Int.right)
                            {
                                OppositeNode.AddNeighbor(node, Vector3Int.left);
                            }
                            else if (dir == Vector3Int.left)
                            {
                                OppositeNode.AddNeighbor(node, Vector3Int.right);
                            }

                            // if current node is a room, but the neighboring is a space tile, this node needs to be checked regularly for changes by other matrices
                            if (OppositeNode.IsRoom && !OppositeNode.MetaDataSystem.externalNodes.ContainsKey(node) && OppositeNode.MetaDataSystem.metaTileMap.IsSpaceAt(OppositeNode.Position, true) == false)
                            {
                                OppositeNode.MetaDataSystem.externalNodes[OppositeNode] = OppositeNode;
                            }

                            // skip other checks for neighboring tile on local tilemap, to prevent the space tile to be added as a neighbor
                            continue;
                        }
                    }
                }
            }

            MetaDataNode neighborNode = metaDataLayer.Get(neighbor);

            if (metaTileMap.IsSpaceAt(neighbor, true))
            {
                neighborNode.Type = NodeType.Space;
            }

            if (neighborNode.Type == NodeType.Space)
            {
                neighborNode.ThermalConductivity = 0.4f;
                neighborNode.HeatCapacity        = 700000f;
            }
            else if (neighborNode.Type == NodeType.Room)
            {
                neighborNode.ThermalConductivity = 0.04f;
                neighborNode.HeatCapacity        = 10000f;
            }

            node.AddNeighbor(neighborNode, dir);
        }
    }