Beispiel #1
0
    public static List <T> GetUpdatedTileModifiersForVariation <T>(Tile tile, T thisMazeTileModifier, string modifierSubtype) where T : MonoBehaviour, ITileConnectable
    {
        Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------");
        TileModifierConnectionInfo <T> connectionRight = new TileModifierConnectionInfo <T>(Direction.Right);
        TileModifierConnectionInfo <T> connectionDown  = new TileModifierConnectionInfo <T>(Direction.Down);
        TileModifierConnectionInfo <T> connectionLeft  = new TileModifierConnectionInfo <T>(Direction.Left);
        TileModifierConnectionInfo <T> connectionUp    = new TileModifierConnectionInfo <T>(Direction.Up);

        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}. We look for a {typeof(T)}");

            T connectedModifier;

            if (typeof(ITileAttribute).IsAssignableFrom(typeof(T)))
            {
                List <ITileAttribute> attributes = neighbour.Value.GetAttributes();
                connectedModifier = (T)attributes.FirstOrDefault(attribute => attribute is T);
            }
            else
            {
                List <ITileBackground> backgrounds = neighbour.Value.GetBackgrounds();

                connectedModifier = (T)backgrounds.FirstOrDefault(background => background is T);
            }

            if (connectedModifier == null || connectedModifier.GetSubtypeAsString() != modifierSubtype)
            {
                continue;
            }

            if (neighbour.Key == ObjectDirection.Right)
            {
                connectionRight.HasConnection = true;
                connectionRight.TileModifier  = connectedModifier;
            }
            else if (neighbour.Key == ObjectDirection.Down)
            {
                connectionDown.HasConnection = true;
                connectionDown.TileModifier  = connectedModifier;
            }
            else if (neighbour.Key == ObjectDirection.Left)
            {
                connectionLeft.HasConnection = true;
                connectionLeft.TileModifier  = connectedModifier;
            }
            else if (neighbour.Key == ObjectDirection.Up)
            {
                connectionUp.HasConnection = true;
                connectionUp.TileModifier  = connectedModifier;
            }
        }

        return(CalculateTileConnectionScoreForVariations(thisMazeTileModifier, connectionRight, connectionDown, connectionLeft, connectionUp));
    }
Beispiel #2
0
    public static TileConnectionScoreInfo MapNeighbourObstaclesOfTile(Tile tile, ObstacleType obstacleType)
    {
        Logger.Log($"Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}");
        TileModifierConnectionInfo <TileObstacle> obstacleRight = new TileModifierConnectionInfo <TileObstacle>(Direction.Right);
        TileModifierConnectionInfo <TileObstacle> obstacleDown  = new TileModifierConnectionInfo <TileObstacle>(Direction.Down);
        TileModifierConnectionInfo <TileObstacle> obstacleLeft  = new TileModifierConnectionInfo <TileObstacle>(Direction.Left);
        TileModifierConnectionInfo <TileObstacle> obstacleUp    = new TileModifierConnectionInfo <TileObstacle>(Direction.Up);

        if (!EditorManager.InEditor)
        {
            Logger.Error("MapNeighbourObstaclesOfTile was not called from the editor");
            return(null);
        }

        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}");

            TileObstacle tileObstacle = neighbour.Value.TryGetTileObstacle();

            if (tileObstacle == null || tileObstacle.ObstacleType != obstacleType)
            {
                continue;
            }

            if (neighbour.Key == ObjectDirection.Right)
            {
                obstacleRight.HasConnection = true;
                obstacleRight.TileModifier  = tileObstacle;
            }
            else if (neighbour.Key == ObjectDirection.Down)
            {
                obstacleDown.HasConnection = true;
                obstacleDown.TileModifier  = tileObstacle;
            }
            else if (neighbour.Key == ObjectDirection.Left)
            {
                obstacleLeft.HasConnection = true;
                obstacleLeft.TileModifier  = tileObstacle;
            }
            else if (neighbour.Key == ObjectDirection.Up)
            {
                obstacleUp.HasConnection = true;
                obstacleUp.TileModifier  = tileObstacle;
            }
        }

        return(TileConnectionRegister.CalculateTileConnectionScore(obstacleRight, obstacleDown, obstacleLeft, obstacleUp));
    }
Beispiel #3
0
    public static TileConnectionScoreInfo CalculateTileConnectionScore <T>(TileModifierConnectionInfo <T> right, TileModifierConnectionInfo <T> down, TileModifierConnectionInfo <T> left, TileModifierConnectionInfo <T> up) where T : MonoBehaviour, ITileConnectable
    {
        int rightConnectionScore = right.TileModifier ? right.TileModifier.ConnectionScore : 16;
        int downConnectionScore  = down.TileModifier ? down.TileModifier.ConnectionScore : 16;
        int leftConnectionScore  = left.TileModifier ? left.TileModifier.ConnectionScore : 16;
        int upConnectionScore    = up.TileModifier ? up.TileModifier.ConnectionScore : 16;

        if (right.HasConnection)
        {
            // narrow
            if (rightConnectionScore == 1 || rightConnectionScore == 2 || rightConnectionScore == 3 || rightConnectionScore == 4 || rightConnectionScore == 5 || rightConnectionScore == 6 || rightConnectionScore == 7 || rightConnectionScore == 8 || rightConnectionScore == 9 || rightConnectionScore == 10 || rightConnectionScore == 11 || rightConnectionScore == 12 || rightConnectionScore == 14 || rightConnectionScore == 15 || rightConnectionScore == 17 || rightConnectionScore == 18 || rightConnectionScore == 20 || rightConnectionScore == 27)
            {
                if (down.HasConnection)
                {
                    // narrow
                    if (downConnectionScore == 1 || downConnectionScore == 2 || downConnectionScore == 3 || downConnectionScore == 4 || downConnectionScore == 5 || downConnectionScore == 6 || downConnectionScore == 7 || downConnectionScore == 8 || downConnectionScore == 9 || downConnectionScore == 10 || downConnectionScore == 11 || downConnectionScore == 13 || downConnectionScore == 14 || downConnectionScore == 15 || downConnectionScore == 17 || downConnectionScore == 19 || downConnectionScore == 20 || downConnectionScore == 28)
                    {
                        if (left.HasConnection)
                        {
                            // narrow
                            if (leftConnectionScore == 1 || leftConnectionScore == 2 || leftConnectionScore == 3 || leftConnectionScore == 4 || leftConnectionScore == 5 || leftConnectionScore == 6 || leftConnectionScore == 7 || leftConnectionScore == 8 || leftConnectionScore == 9 || leftConnectionScore == 10 || leftConnectionScore == 11 || leftConnectionScore == 12 || leftConnectionScore == 13 || leftConnectionScore == 14 || leftConnectionScore == 18 || leftConnectionScore == 19 || leftConnectionScore == 20 || leftConnectionScore == 29)
                            {
                                if (up.HasConnection)
                                {
                                    return(new TileConnectionScoreInfo(16));
                                }
                                return(new TileConnectionScoreInfo(12));
                            }
                            // wide
                            if (up.HasConnection)
                            {
                                return(new TileConnectionScoreInfo(16));
                            }
                            return(new TileConnectionScoreInfo(31));
                        }
                        if (up.HasConnection)
                        {
                            // narrow
                            if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                            {
                                return(new TileConnectionScoreInfo(13));
                            }
                            // wide
                            return(new TileConnectionScoreInfo(32));
                        }
                        return(new TileConnectionScoreInfo(6));
                    }
                    else // wide
                    {
                        if (left.HasConnection)
                        {
                            if (up.HasConnection)
                            {
                                return(new TileConnectionScoreInfo(16));
                            }
                            return(new TileConnectionScoreInfo(31));
                        }
                        if (up.HasConnection)
                        {
                            return(new TileConnectionScoreInfo(32));
                        }
                        return(new TileConnectionScoreInfo(21));
                    }
                }
                if (left.HasConnection)
                {
                    // narrow
                    if (leftConnectionScore == 1 || leftConnectionScore == 2 || leftConnectionScore == 3 || leftConnectionScore == 4 || leftConnectionScore == 5 || leftConnectionScore == 6 || leftConnectionScore == 7 || leftConnectionScore == 8 || leftConnectionScore == 9 || leftConnectionScore == 10 || leftConnectionScore == 11 || leftConnectionScore == 12 || leftConnectionScore == 13 || leftConnectionScore == 14 || leftConnectionScore == 18 || leftConnectionScore == 19 || leftConnectionScore == 20 || leftConnectionScore == 29)
                    {
                        if (up.HasConnection)
                        {
                            // narrow
                            if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                            {
                                return(new TileConnectionScoreInfo(14));
                            }
                            // wide
                            return(new TileConnectionScoreInfo(33));
                        }
                        return(new TileConnectionScoreInfo(7));
                    }
                    // wide left
                    if (up.HasConnection)
                    {
                        return(new TileConnectionScoreInfo(33));
                    }
                    return(new TileConnectionScoreInfo(29));
                }
                if (up.HasConnection)
                {
                    // narrow
                    if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                    {
                        return(new TileConnectionScoreInfo(8));
                    }
                    // wide
                    return(new TileConnectionScoreInfo(23));
                }
                return(new TileConnectionScoreInfo(2));
            }
            // wide right
            if (down.HasConnection)
            {
                if (left.HasConnection)
                {
                    if (up.HasConnection)
                    {
                        return(new TileConnectionScoreInfo(16));
                    }
                    return(new TileConnectionScoreInfo(31));
                }
                if (up.HasConnection)
                {
                    return(new TileConnectionScoreInfo(32));
                }
                return(new TileConnectionScoreInfo(21));
            }
            if (left.HasConnection)
            {
                if (up.HasConnection)
                {
                    return(new TileConnectionScoreInfo(33));
                }
                // narrow
                if (leftConnectionScore == 1 || leftConnectionScore == 2 || leftConnectionScore == 3 || leftConnectionScore == 4 || leftConnectionScore == 5 || leftConnectionScore == 6 || leftConnectionScore == 7 || leftConnectionScore == 8 || leftConnectionScore == 9 || leftConnectionScore == 10 || leftConnectionScore == 11 || leftConnectionScore == 12 || leftConnectionScore == 13 || leftConnectionScore == 14 || leftConnectionScore == 18 || leftConnectionScore == 19 || leftConnectionScore == 20 || leftConnectionScore == 29)
                {
                    return(new TileConnectionScoreInfo(27));
                }
                return(new TileConnectionScoreInfo(22));
            }
            if (up.HasConnection)
            {
                return(new TileConnectionScoreInfo(23));
            }
            return(new TileConnectionScoreInfo(17));
        }
        if (down.HasConnection)
        {
            // narrow
            if (downConnectionScore == 1 || downConnectionScore == 2 || downConnectionScore == 3 || downConnectionScore == 4 || downConnectionScore == 5 || downConnectionScore == 6 || downConnectionScore == 7 || downConnectionScore == 8 || downConnectionScore == 9 || downConnectionScore == 10 || downConnectionScore == 11 || downConnectionScore == 13 || downConnectionScore == 14 || downConnectionScore == 15 || downConnectionScore == 17 || downConnectionScore == 18 || downConnectionScore == 19 || downConnectionScore == 20 || downConnectionScore == 28)
            {
                if (left.HasConnection)
                {
                    // left = narrow
                    if (leftConnectionScore == 1 || leftConnectionScore == 2 || leftConnectionScore == 3 || leftConnectionScore == 4 || leftConnectionScore == 5 || leftConnectionScore == 6 || leftConnectionScore == 7 || leftConnectionScore == 8 || leftConnectionScore == 9 || leftConnectionScore == 10 || leftConnectionScore == 11 || leftConnectionScore == 12 || leftConnectionScore == 13 || leftConnectionScore == 14 || leftConnectionScore == 18 || leftConnectionScore == 19 || leftConnectionScore == 20 || leftConnectionScore == 29)
                    {
                        if (up.HasConnection)
                        {
                            // narrow
                            if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                            {
                                return(new TileConnectionScoreInfo(15));
                            }
                            return(new TileConnectionScoreInfo(34));
                        }
                        return(new TileConnectionScoreInfo(9));
                    }
                    // left = wide
                    if (up.HasConnection)
                    {
                        return(new TileConnectionScoreInfo(34));
                    }
                    return(new TileConnectionScoreInfo(25));
                }
                if (up.HasConnection)
                {
                    // narrow
                    if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 21 || upConnectionScore == 25 || upConnectionScore == 30)
                    {
                        return(new TileConnectionScoreInfo(10));
                    }
                    if (upConnectionScore == 24 || upConnectionScore == 28)
                    {
                        return(new TileConnectionScoreInfo(30));
                    }
                    // wide
                    return(new TileConnectionScoreInfo(24));
                }
                return(new TileConnectionScoreInfo(3));
            }
            // wide down
            if (left.HasConnection)
            {
                if (up.HasConnection)
                {
                    return(new TileConnectionScoreInfo(34));
                }
                return(new TileConnectionScoreInfo(25));
            }
            if (up.HasConnection)
            {
                // narrow
                if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                {
                    return(new TileConnectionScoreInfo(28));
                }
                return(new TileConnectionScoreInfo(24));
            }
            return(new TileConnectionScoreInfo(18));
        }

        if (left.HasConnection)
        {
            // narrow
            if (leftConnectionScore == 1 || leftConnectionScore == 2 || leftConnectionScore == 3 || leftConnectionScore == 4 || leftConnectionScore == 5 || leftConnectionScore == 6 || leftConnectionScore == 7 || leftConnectionScore == 8 || leftConnectionScore == 9 || leftConnectionScore == 10 || leftConnectionScore == 11 || leftConnectionScore == 12 || leftConnectionScore == 13 || leftConnectionScore == 14 || leftConnectionScore == 18 || leftConnectionScore == 19 || leftConnectionScore == 20 || leftConnectionScore == 29)
            {
                if (up.HasConnection)
                {
                    // narrow
                    if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
                    {
                        return(new TileConnectionScoreInfo(11));
                    }
                    return(new TileConnectionScoreInfo(26));
                }
                return(new TileConnectionScoreInfo(4));
            }
            // wide
            if (up.HasConnection)
            {
                return(new TileConnectionScoreInfo(26));
            }
            return(new TileConnectionScoreInfo(19));
        }
        if (up.HasConnection)
        {
            // narrow
            if (upConnectionScore == 1 || upConnectionScore == 2 || upConnectionScore == 3 || upConnectionScore == 4 || upConnectionScore == 5 || upConnectionScore == 6 || upConnectionScore == 7 || upConnectionScore == 8 || upConnectionScore == 9 || upConnectionScore == 10 || upConnectionScore == 11 || upConnectionScore == 12 || upConnectionScore == 13 || upConnectionScore == 15 || upConnectionScore == 17 || upConnectionScore == 18 || upConnectionScore == 19 || upConnectionScore == 20 || upConnectionScore == 30)
            {
                return(new TileConnectionScoreInfo(5));
            }
            return(new TileConnectionScoreInfo(20));
        }
        return(new TileConnectionScoreInfo(1));
    }
Beispiel #4
0
    public static TileConnectionScoreInfo CalculateInversedTileConnectionScore <T>(TileModifierConnectionInfo <T> right, TileModifierConnectionInfo <T> down, TileModifierConnectionInfo <T> left, TileModifierConnectionInfo <T> up) where T : MonoBehaviour, ITileConnectable
    {
        int rightConnectionScore = right.TileModifier ? right.TileModifier.ConnectionScore : 16;
        int downConnectionScore  = down.TileModifier ? down.TileModifier.ConnectionScore : 16;
        int leftConnectionScore  = left.TileModifier ? left.TileModifier.ConnectionScore : 16;
        int upConnectionScore    = up.TileModifier ? up.TileModifier.ConnectionScore : 16;

        if (right.HasConnection)
        {
            //if(right.TileModifier.ConnectionScore == 16)
            //{
            if (down.HasConnection)
            {
                if (left.HasConnection)
                {
                    if (up.HasConnection)
                    {
                        //Should this be an empty tile??? connections from all sides
                        return(new TileConnectionScoreInfo(1));
                    }
                    //return new TileConnectionScoreInfo(5);
                    return(new TileConnectionScoreInfo(20));
                }
                if (up.HasConnection)
                {
                    //return new TileConnectionScoreInfo(4);
                    return(new TileConnectionScoreInfo(19));
                }
                //return new TileConnectionScoreInfo(11);
                return(new TileConnectionScoreInfo(26));
            }
            if (left.HasConnection)
            {
                if (up.HasConnection)
                {
                    //return new TileConnectionScoreInfo(3);
                    return(new TileConnectionScoreInfo(18));
                }
                //return new TileConnectionScoreInfo(10);
                return(new TileConnectionScoreInfo(24));
            }
            if (up.HasConnection)
            {
                //return new TileConnectionScoreInfo(9);
                return(new TileConnectionScoreInfo(25));
            }
            //return new TileConnectionScoreInfo(15);
            return(new TileConnectionScoreInfo(34));
            //}
        }
        if (down.HasConnection)
        {
            if (left.HasConnection)
            {
                //if (left.TileModifier.ConnectionScore == 16)
                //{
                if (up.HasConnection)
                {
                    //return new TileConnectionScoreInfo(2);
                    return(new TileConnectionScoreInfo(17));
                }
                //return new TileConnectionScoreInfo(8);
                return(new TileConnectionScoreInfo(23));
                //}
                //return new TileConnectionScoreInfo(4);
            }
            if (up.HasConnection)
            {
                //return new TileConnectionScoreInfo(7);
                return(new TileConnectionScoreInfo(22));
            }
            //return new TileConnectionScoreInfo(14);
            return(new TileConnectionScoreInfo(33));
        }
        if (left.HasConnection)
        {
            if (up.HasConnection)
            {
                //return new TileConnectionScoreInfo(6);
                return(new TileConnectionScoreInfo(21));
            }
            //return new TileConnectionScoreInfo(13);
            return(new TileConnectionScoreInfo(32));
        }
        if (up.HasConnection)
        {
            //return new TileConnectionScoreInfo(12);
            return(new TileConnectionScoreInfo(31));
        }
        return(new TileConnectionScoreInfo(-1));
    }
Beispiel #5
0
    public static TileConnectionScoreInfo MapNeighbourPathsOfTile(Tile tile, IPathType pathType)
    {
        Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------");
        TileModifierConnectionInfo <TilePath> pathRight = new TileModifierConnectionInfo <TilePath>(Direction.Right);
        TileModifierConnectionInfo <TilePath> pathDown  = new TileModifierConnectionInfo <TilePath>(Direction.Down);
        TileModifierConnectionInfo <TilePath> pathLeft  = new TileModifierConnectionInfo <TilePath>(Direction.Left);
        TileModifierConnectionInfo <TilePath> pathUp    = new TileModifierConnectionInfo <TilePath>(Direction.Up);

        if (!EditorManager.InEditor)
        {
            Logger.Error("MapNeighbourPathsOfTile was not called from the editor");
            return(null);
        }

        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                // if there is no tile as neighbour, it must mean it as the level edge. This counts as a connection.
                if (neighbour.Key == ObjectDirection.Right)
                {
                    pathRight.HasConnection = true;
                }
                else if (neighbour.Key == ObjectDirection.Down)
                {
                    pathDown.HasConnection = true;
                }
                else if (neighbour.Key == ObjectDirection.Left)
                {
                    pathLeft.HasConnection = true;
                }
                else if (neighbour.Key == ObjectDirection.Up)
                {
                    pathUp.HasConnection = true;
                }
                continue;
            }

            Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}.");

            // Check if the neighbour has a connection which is a PATH or a BRIDGE
            TilePath tilePath = neighbour.Value.TryGetTilePath();
            if (tilePath == null || tilePath.TilePathType?.GetType() != pathType.GetType())
            {
                BridgePiece bridgePiece = neighbour.Value.TryGetBridgePiece();
                if (bridgePiece == null)
                {
                    continue;
                }

                bool hasBridgeConnection = false;

                if ((neighbour.Key == ObjectDirection.Right || neighbour.Key == ObjectDirection.Left) &&
                    bridgePiece.BridgePieceDirection == BridgePieceDirection.Horizontal)
                {
                    hasBridgeConnection = true;
                }
                else if ((neighbour.Key == ObjectDirection.Down || neighbour.Key == ObjectDirection.Up) &&
                         bridgePiece.BridgePieceDirection == BridgePieceDirection.Vertical)
                {
                    hasBridgeConnection = true;
                }

                if (hasBridgeConnection == false)
                {
                    continue;
                }
            }

            if (neighbour.Key == ObjectDirection.Right)
            {
                pathRight.HasConnection = true;
                pathRight.TileModifier  = tilePath;
            }
            else if (neighbour.Key == ObjectDirection.Down)
            {
                pathDown.HasConnection = true;
                pathDown.TileModifier  = tilePath;
            }
            else if (neighbour.Key == ObjectDirection.Left)
            {
                pathLeft.HasConnection = true;
                pathLeft.TileModifier  = tilePath;
            }
            else if (neighbour.Key == ObjectDirection.Up)
            {
                pathUp.HasConnection = true;
                pathUp.TileModifier  = tilePath;
            }
        }

        return(TileConnectionRegister.CalculateTileConnectionScore(pathRight, pathDown, pathLeft, pathUp));
    }
Beispiel #6
0
    private static List <T> CalculateTileConnectionScoreForVariations <T>(T thisMazeTileAttribute, TileModifierConnectionInfo <T> connectionRight, TileModifierConnectionInfo <T> connectionDown, TileModifierConnectionInfo <T> connectionLeft, TileModifierConnectionInfo <T> connectionUp) where T : MonoBehaviour, ITileConnectable
    {
        TileConnectionVariationRegister <T> TileConnectionVariationRegister = new TileConnectionVariationRegister <T>(thisMazeTileAttribute, connectionRight, connectionDown, connectionLeft, connectionUp);
        Type modifierType = typeof(T);

        if (modifierType == typeof(TilePath) || modifierType == typeof(TileBaseGround))
        {
            return(TileConnectionVariationRegister.MazeTileBackgroundConnection());
        }
        else if (modifierType == typeof(TileObstacle))
        {
            return(TileConnectionVariationRegister.TileAttribute() as List <T>);
        }
        else
        {
            Logger.Error($"Type {modifierType} was not yet implemented for Tile Connection Register");
            return(null);
        }
    }
Beispiel #7
0
    public static TileConnectionScoreInfo MapGroundConnectionsWithNeighbours(Tile tile, IBaseBackgroundType groundType)
    {
        Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------");
        TileModifierConnectionInfo <TileBaseGround> groundRight = new TileModifierConnectionInfo <TileBaseGround>(Direction.Right);
        TileModifierConnectionInfo <TileBaseGround> groundDown  = new TileModifierConnectionInfo <TileBaseGround>(Direction.Down);
        TileModifierConnectionInfo <TileBaseGround> groundLeft  = new TileModifierConnectionInfo <TileBaseGround>(Direction.Left);
        TileModifierConnectionInfo <TileBaseGround> groundUp    = new TileModifierConnectionInfo <TileBaseGround>(Direction.Up);

        if (!EditorManager.InEditor)
        {
            Logger.Error("MapNeighbourGroundOfTile was not called from the editor");
            return(null);
        }

        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                // if there is no tile as neighbour, it must mean it as the level edge. This counts as a connection.
                // But only if the main tile itself is a land tile
                if (tile.TileMainMaterial.GetType() == typeof(GroundMainMaterial))
                {
                    if (neighbour.Key == ObjectDirection.Right)
                    {
                        groundRight.HasConnection = true;
                    }
                    else if (neighbour.Key == ObjectDirection.Down)
                    {
                        groundDown.HasConnection = true;
                    }
                    else if (neighbour.Key == ObjectDirection.Left)
                    {
                        groundLeft.HasConnection = true;
                    }
                    else if (neighbour.Key == ObjectDirection.Up)
                    {
                        groundUp.HasConnection = true;
                    }
                }
                continue;
            }

            Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}. Its main material is {neighbour.Value.TileMainMaterial.GetType()}");

            TileBaseGround tileGround = neighbour.Value.TryGetTileGround();
            //if (tileGround == null || tileGround.TileGroundType.GetType() != groundType.GetType())
            //{
            //    continue;
            //}

            if (neighbour.Value.TileMainMaterial?.GetType() != typeof(GroundMainMaterial))
            {
                continue;
            }

            if (neighbour.Key == ObjectDirection.Right)
            {
                groundRight.HasConnection = true;
                groundRight.TileModifier  = tileGround;
            }
            else if (neighbour.Key == ObjectDirection.Down)
            {
                groundDown.HasConnection = true;
                groundDown.TileModifier  = tileGround;
            }
            else if (neighbour.Key == ObjectDirection.Left)
            {
                groundLeft.HasConnection = true;
                groundLeft.TileModifier  = tileGround;
            }
            else if (neighbour.Key == ObjectDirection.Up)
            {
                groundUp.HasConnection = true;
                groundUp.TileModifier  = tileGround;
            }
        }

        return(TileConnectionRegister.CalculateInversedTileConnectionScore(groundRight, groundDown, groundLeft, groundUp));
    }