Exemplo n.º 1
0
        public TileOrientationChance GetRandom()
        {
            TileOrientationChance ReturnResult = new TileOrientationChance();
            int A = 0;
            int intRandom = 0;
            int Total = 0;

            intRandom = (int)(Conversion.Int(VBMath.Rnd() * TileChanceTotal));
            for ( A = 0; A <= TileCount - 1; A++ )
            {
                Total += Convert.ToInt32(Tiles[A].Chance);
                if ( intRandom < Total )
                {
                    break;
                }
            }
            if ( A == TileCount )
            {
                ReturnResult.TextureNum = -1;
                ReturnResult.Direction = TileUtil.None;
            }
            else
            {
                ReturnResult = Tiles[A];
            }
            return ReturnResult;
        }
Exemplo n.º 2
0
        public TileOrientationChance GetRandom()
        {
            var ReturnResult = new TileOrientationChance();
            var A = 0;
            var intRandom = 0;
            var Total = 0;

            var rnd = new Random();
            intRandom = rnd.Next() * TileChanceTotal;
            for ( A = 0; A <= TileCount - 1; A++ )
            {
                Total += Convert.ToInt32(Tiles[A].Chance);
                if ( intRandom < Total )
                {
                    break;
                }
            }
            if ( A == TileCount )
            {
                ReturnResult.TextureNum = -1;
                ReturnResult.Direction = TileUtil.None;
            }
            else
            {
                ReturnResult = Tiles[A];
            }
            return ReturnResult;
        }
Exemplo n.º 3
0
            public override void ActionPerform()
            {
                Terrain = Map.Terrain;

                Painter = Map.Painter;

                ResultTiles = null;
                ResultDirection = TileUtil.None;

                //apply centre brushes
                if ( !Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff )
                {
                    for ( int BrushNum = 0; BrushNum <= Painter.TerrainCount - 1; BrushNum++ )
                    {
                        Terrain_Inner = Painter.Terrains[BrushNum];
                        if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                        {
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                            {
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //i i i i
                                        ResultTiles = Terrain_Inner.Tiles;
                                        ResultDirection = TileUtil.None;
                                    }
                                }
                            }
                        }
                    }
                }

                //apply transition brushes
                if ( !Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff )
                {
                    for ( int BrushNum = 0; BrushNum <= Painter.TransitionBrushCount - 1; BrushNum++ )
                    {
                        Terrain_Inner = Painter.TransitionBrushes[BrushNum].Terrain_Inner;
                        Terrain_Outer = Painter.TransitionBrushes[BrushNum].Terrain_Outer;
                        if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                        {
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                            {
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //i i i i
                                        //nothing to do here
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //i i i o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.BottomRight;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //i i o i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.BottomLeft;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //i i o o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = TileUtil.Bottom;
                                        break;
                                    }
                                }
                            }
                            else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                            {
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //i o i i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.TopRight;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //i o i o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = TileUtil.Right;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //i o o i
                                        ResultTiles = null;
                                        ResultDirection = TileUtil.None;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //i o o o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.BottomRight;
                                        break;
                                    }
                                }
                            }
                        }
                        else if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                        {
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                            {
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //o i i i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.TopLeft;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //o i i o
                                        ResultTiles = null;
                                        ResultDirection = TileUtil.None;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //o i o i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = TileUtil.Left;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //o i o o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.BottomLeft;
                                        break;
                                    }
                                }
                            }
                            else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                            {
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //o o i i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = TileUtil.Top;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //o o i o
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.TopRight;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        //o o o i
                                        ResultTiles = Painter.TransitionBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.TopLeft;
                                        break;
                                    }
                                    else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        //o o o o
                                        //nothing to do here
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                //set cliff tiles
                if ( Terrain.Tiles[PosNum.X, PosNum.Y].Tri )
                {
                    if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriTopLeftIsCliff )
                    {
                        if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff )
                        {
                            int BrushNum = 0;
                            for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                            {
                                Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                                Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                                if ( Terrain_Inner == Terrain_Outer )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( A >= 3 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = Terrain.Tiles[PosNum.X, PosNum.Y].DownSide;
                                        break;
                                    }
                                }
                                if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner && Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner) &&
                                      (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer ||
                                       Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) ||
                                     ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner || Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner) &&
                                      (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer &&
                                       Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Bottom;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Left;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Top;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Right;
                                    break;
                                }
                            }
                            if ( BrushNum == Painter.CliffBrushCount )
                            {
                                ResultTiles = null;
                                ResultDirection = TileUtil.None;
                            }
                        }
                        else
                        {
                            int BrushNum = 0;
                            for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                            {
                                Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                                Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( A >= 2 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.TopLeft;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( A >= 2 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.BottomRight;
                                        break;
                                    }
                                }
                            }
                            if ( BrushNum == Painter.CliffBrushCount )
                            {
                                ResultTiles = null;
                                ResultDirection = TileUtil.None;
                            }
                        }
                    }
                    else if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff )
                    {
                        int BrushNum = 0;
                        for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                        {
                            Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                            Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                            {
                                int A = 0;
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( A >= 2 )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_In;
                                    ResultDirection = TileUtil.BottomRight;
                                    break;
                                }
                            }
                            else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                            {
                                int A = 0;
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( A >= 2 )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_Out;
                                    ResultDirection = TileUtil.TopLeft;
                                    break;
                                }
                            }
                        }
                        if ( BrushNum == Painter.CliffBrushCount )
                        {
                            ResultTiles = null;
                            ResultDirection = TileUtil.None;
                        }
                    }
                    else
                    {
                        //no cliff
                    }
                }
                else
                {
                    //default tri orientation
                    if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriTopRightIsCliff )
                    {
                        if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff )
                        {
                            int BrushNum = 0;
                            for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                            {
                                Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                                Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                                if ( Terrain_Inner == Terrain_Outer )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( A >= 3 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                        ResultDirection = Terrain.Tiles[PosNum.X, PosNum.Y].DownSide;
                                        break;
                                    }
                                }
                                if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner && Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner) &&
                                      (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer ||
                                       Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) ||
                                     ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner || Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner) &&
                                      (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer &&
                                       Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Bottom;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Left;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer) &&
                                           (Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Top;
                                    break;
                                }
                                else if ( ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner &&
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer ||
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) ||
                                          ((Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner ||
                                            Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner) &&
                                           (Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer &&
                                            Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer)) )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Straight;
                                    ResultDirection = TileUtil.Right;
                                    break;
                                }
                            }
                            if ( BrushNum == Painter.CliffBrushCount )
                            {
                                ResultTiles = null;
                                ResultDirection = TileUtil.None;
                            }
                        }
                        else
                        {
                            int BrushNum = 0;
                            for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                            {
                                Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                                Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                    {
                                        A++;
                                    }
                                    if ( A >= 2 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_In;
                                        ResultDirection = TileUtil.TopRight;
                                        break;
                                    }
                                }
                                else if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    int A = 0;
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                    {
                                        A++;
                                    }
                                    if ( A >= 2 )
                                    {
                                        ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_Out;
                                        ResultDirection = TileUtil.BottomLeft;
                                        break;
                                    }
                                }
                            }
                            if ( BrushNum == Painter.CliffBrushCount )
                            {
                                ResultTiles = null;
                                ResultDirection = TileUtil.None;
                            }
                        }
                    }
                    else if ( Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff )
                    {
                        int BrushNum = 0;
                        for ( BrushNum = 0; BrushNum <= Painter.CliffBrushCount - 1; BrushNum++ )
                        {
                            Terrain_Inner = Painter.CliffBrushes[BrushNum].Terrain_Inner;
                            Terrain_Outer = Painter.CliffBrushes[BrushNum].Terrain_Outer;
                            if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                            {
                                int A = 0;
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Inner )
                                {
                                    A++;
                                }
                                if ( A >= 2 )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_In;
                                    ResultDirection = TileUtil.BottomLeft;
                                    break;
                                }
                            }
                            else if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Inner )
                            {
                                int A = 0;
                                if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                                {
                                    A++;
                                }
                                if ( A >= 2 )
                                {
                                    ResultTiles = Painter.CliffBrushes[BrushNum].Tiles_Corner_Out;
                                    ResultDirection = TileUtil.TopRight;
                                    break;
                                }
                            }
                        }
                        if ( BrushNum == Painter.CliffBrushCount )
                        {
                            ResultTiles = null;
                            ResultDirection = TileUtil.None;
                        }
                    }
                    else
                    {
                        //no cliff
                    }
                }

                //apply roads
                Road = null;
                if ( Terrain.SideH[PosNum.X, PosNum.Y].Road != null )
                {
                    Road = Terrain.SideH[PosNum.X, PosNum.Y].Road;
                }
                else if ( Terrain.SideH[PosNum.X, PosNum.Y + 1].Road != null )
                {
                    Road = Terrain.SideH[PosNum.X, PosNum.Y + 1].Road;
                }
                else if ( Terrain.SideV[PosNum.X + 1, PosNum.Y].Road != null )
                {
                    Road = Terrain.SideV[PosNum.X + 1, PosNum.Y].Road;
                }
                else if ( Terrain.SideV[PosNum.X, PosNum.Y].Road != null )
                {
                    Road = Terrain.SideV[PosNum.X, PosNum.Y].Road;
                }
                if ( Road != null )
                {
                    int BrushNum = 0;
                    for ( BrushNum = 0; BrushNum <= Painter.RoadBrushCount - 1; BrushNum++ )
                    {
                        if ( Painter.RoadBrushes[BrushNum].Road == Road )
                        {
                            Terrain_Outer = Painter.RoadBrushes[BrushNum].Terrain;
                            int A = 0;
                            if ( Terrain.Vertices[PosNum.X, PosNum.Y].Terrain == Terrain_Outer )
                            {
                                A++;
                            }
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y].Terrain == Terrain_Outer )
                            {
                                A++;
                            }
                            if ( Terrain.Vertices[PosNum.X, PosNum.Y + 1].Terrain == Terrain_Outer )
                            {
                                A++;
                            }
                            if ( Terrain.Vertices[PosNum.X + 1, PosNum.Y + 1].Terrain == Terrain_Outer )
                            {
                                A++;
                            }
                            if ( A >= 2 )
                            {
                                break;
                            }
                        }
                    }

                    ResultTiles = null;
                    ResultDirection = TileUtil.None;

                    if ( BrushNum < Painter.RoadBrushCount )
                    {
                        RoadTop = Terrain.SideH[PosNum.X, PosNum.Y].Road == Road;
                        RoadLeft = Terrain.SideV[PosNum.X, PosNum.Y].Road == Road;
                        RoadRight = Terrain.SideV[PosNum.X + 1, PosNum.Y].Road == Road;
                        RoadBottom = Terrain.SideH[PosNum.X, PosNum.Y + 1].Road == Road;
                        //do cross intersection
                        if ( RoadTop && RoadLeft && RoadRight && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_CrossIntersection;
                            ResultDirection = TileUtil.None;
                            //do T intersection
                        }
                        else if ( RoadTop && RoadLeft && RoadRight )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_TIntersection;
                            ResultDirection = TileUtil.Top;
                        }
                        else if ( RoadTop && RoadLeft && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_TIntersection;
                            ResultDirection = TileUtil.Left;
                        }
                        else if ( RoadTop && RoadRight && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_TIntersection;
                            ResultDirection = TileUtil.Right;
                        }
                        else if ( RoadLeft && RoadRight && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_TIntersection;
                            ResultDirection = TileUtil.Bottom;
                            //do straight
                        }
                        else if ( RoadTop && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Straight;
                            if ( VBMath.Rnd() >= 0.5F )
                            {
                                ResultDirection = TileUtil.Top;
                            }
                            else
                            {
                                ResultDirection = TileUtil.Bottom;
                            }
                        }
                        else if ( RoadLeft && RoadRight )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Straight;
                            if ( VBMath.Rnd() >= 0.5F )
                            {
                                ResultDirection = TileUtil.Left;
                            }
                            else
                            {
                                ResultDirection = TileUtil.Right;
                            }
                            //do corner
                        }
                        else if ( RoadTop && RoadLeft )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Corner_In;
                            ResultDirection = TileUtil.TopLeft;
                        }
                        else if ( RoadTop && RoadRight )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Corner_In;
                            ResultDirection = TileUtil.TopRight;
                        }
                        else if ( RoadLeft && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Corner_In;
                            ResultDirection = TileUtil.BottomLeft;
                        }
                        else if ( RoadRight && RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_Corner_In;
                            ResultDirection = TileUtil.BottomRight;
                            //do end
                        }
                        else if ( RoadTop )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_End;
                            ResultDirection = TileUtil.Top;
                        }
                        else if ( RoadLeft )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_End;
                            ResultDirection = TileUtil.Left;
                        }
                        else if ( RoadRight )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_End;
                            ResultDirection = TileUtil.Right;
                        }
                        else if ( RoadBottom )
                        {
                            ResultTiles = Painter.RoadBrushes[BrushNum].Tile_End;
                            ResultDirection = TileUtil.Bottom;
                        }
                    }
                }

                if ( ResultTiles == null )
                {
                    ResultTexture.TextureNum = -1;
                    ResultTexture.Direction = TileUtil.None;
                }
                else
                {
                    ResultTexture = ResultTiles.GetRandom();
                }
                if ( ResultTexture.TextureNum < 0 )
                {
                    if ( MakeInvalidTiles )
                    {
                        Terrain.Tiles[PosNum.X, PosNum.Y].Texture = TileUtil.OrientateTile(ResultTexture, ResultDirection);
                    }
                }
                else
                {
                    Terrain.Tiles[PosNum.X, PosNum.Y].Texture = TileUtil.OrientateTile(ResultTexture, ResultDirection);
                }

                Map.SectorGraphicsChanges.TileChanged(PosNum);
                Map.SectorTerrainUndoChanges.TileChanged(PosNum);
            }
        public override void ActionPerform()
        {
            var PainterBrushNum = 0;
            var A = 0;

            Terrain = Map.Terrain;

            Painter = Map.Painter;

            Tile = Terrain.Tiles[PosNum.X, PosNum.Y];
            Texture = Tile.Texture;

            Terrain.Tiles[PosNum.X, PosNum.Y].TriTopLeftIsCliff = false;
            Terrain.Tiles[PosNum.X, PosNum.Y].TriTopRightIsCliff = false;
            Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff = false;
            Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff = false;
            Terrain.Tiles[PosNum.X, PosNum.Y].DownSide = TileUtil.None;

            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.CliffBrushCount - 1; PainterBrushNum++ )
            {
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Straight.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Straight.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        if ( Tile.Tri )
                        {
                            Terrain.Tiles[PosNum.X, PosNum.Y].TriTopLeftIsCliff = true;
                            Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff = true;
                        }
                        else
                        {
                            Terrain.Tiles[PosNum.X, PosNum.Y].TriTopRightIsCliff = true;
                            Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff = true;
                        }
                        Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        Terrain.Tiles[PosNum.X, PosNum.Y].DownSide = ResultDirection;
                    }
                }
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_In.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_In.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( Tile.Tri )
                        {
                            if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.TopLeft) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriTopLeftIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                            else if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.BottomRight) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                        }
                        else
                        {
                            if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.TopRight) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriTopRightIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                            else if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.BottomLeft) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                        }
                    }
                }
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_Out.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_Out.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        OppositeDirection = PainterTexture.Direction;
                        OppositeDirection.FlipX();
                        OppositeDirection.FlipY();
                        TileUtil.RotateDirection(OppositeDirection, Texture.Orientation, ref ResultDirection);
                        if ( Tile.Tri )
                        {
                            if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.TopLeft) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriTopLeftIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                            else if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.BottomRight) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomRightIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                        }
                        else
                        {
                            if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.TopRight) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriTopRightIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                            else if ( TileUtil.IdenticalTileDirections(ResultDirection, TileUtil.BottomLeft) )
                            {
                                Terrain.Tiles[PosNum.X, PosNum.Y].TriBottomLeftIsCliff = true;
                                Terrain.Tiles[PosNum.X, PosNum.Y].Terrain_IsCliff = true;
                            }
                        }
                    }
                }
            }

            Map.SectorTerrainUndoChanges.TileChanged(PosNum);
        }
Exemplo n.º 5
0
        public static clsMap.clsTerrain.Tile.sTexture OrientateTile(TileOrientationChance tileChance, TileDirection newDirection)
        {
            clsMap.clsTerrain.Tile.sTexture ReturnResult = new clsMap.clsTerrain.Tile.sTexture();

            //use random for empty tiles
            if ( tileChance.TextureNum < 0 )
            {
                ReturnResult.Orientation.ResultXFlip = VBMath.Rnd() >= 0.5F;
                ReturnResult.Orientation.ResultYFlip = VBMath.Rnd() >= 0.5F;
                ReturnResult.Orientation.SwitchedAxes = VBMath.Rnd() >= 0.5F;
                ReturnResult.TextureNum = -1;
                return ReturnResult;
            }
            //stop invalid numbers
            if ( tileChance.Direction.X > 2 | tileChance.Direction.Y > 2 | newDirection.X > 2 | newDirection.Y > 2 )
            {
                Debugger.Break();
                return ReturnResult;
            }
            //stop different direction types
            if ( (newDirection.X == 1 ^ newDirection.Y == 1) ^ (tileChance.Direction.X == 1 ^ tileChance.Direction.Y == 1) )
            {
                Debugger.Break();
                return ReturnResult;
            }

            ReturnResult.TextureNum = tileChance.TextureNum;

            //if a direction is neutral then give a random orientation
            if ( (newDirection.X == 1 & newDirection.Y == 1) || (tileChance.Direction.X == 1 & tileChance.Direction.Y == 1) )
            {
                ReturnResult.Orientation.SwitchedAxes = VBMath.Rnd() >= 0.5F;
                ReturnResult.Orientation.ResultXFlip = VBMath.Rnd() >= 0.5F;
                ReturnResult.Orientation.ResultYFlip = VBMath.Rnd() >= 0.5F;
                return ReturnResult;
            }

            bool IsDiagonal = default(bool);

            IsDiagonal = newDirection.X != 1 & newDirection.Y != 1;
            if ( IsDiagonal )
            {
                ReturnResult.Orientation.SwitchedAxes = false;
                //use flips to match the directions
                if ( tileChance.Direction.X == 0 ^ newDirection.X == 0 )
                {
                    ReturnResult.Orientation.ResultXFlip = true;
                }
                else
                {
                    ReturnResult.Orientation.ResultXFlip = false;
                }
                if ( tileChance.Direction.Y == 0 ^ newDirection.Y == 0 )
                {
                    ReturnResult.Orientation.ResultYFlip = true;
                }
                else
                {
                    ReturnResult.Orientation.ResultYFlip = false;
                }
                //randomly switch to the alternate orientation
                if ( VBMath.Rnd() >= 0.5F )
                {
                    ReturnResult.Orientation.SwitchedAxes = !ReturnResult.Orientation.SwitchedAxes;
                    if ( (newDirection.X == 0 ^ newDirection.Y == 0) ^ (ReturnResult.Orientation.ResultXFlip ^ ReturnResult.Orientation.ResultYFlip) )
                    {
                        ReturnResult.Orientation.ResultXFlip = !ReturnResult.Orientation.ResultXFlip;
                        ReturnResult.Orientation.ResultYFlip = !ReturnResult.Orientation.ResultYFlip;
                    }
                }
            }
            else
            {
                //switch axes if the directions are on different axes
                ReturnResult.Orientation.SwitchedAxes = tileChance.Direction.X == 1 ^ newDirection.X == 1;
                //use a flip to match the directions
                if ( ReturnResult.Orientation.SwitchedAxes )
                {
                    if ( tileChance.Direction.Y != newDirection.X )
                    {
                        ReturnResult.Orientation.ResultXFlip = true;
                    }
                    else
                    {
                        ReturnResult.Orientation.ResultXFlip = false;
                    }
                    if ( tileChance.Direction.X != newDirection.Y )
                    {
                        ReturnResult.Orientation.ResultYFlip = true;
                    }
                    else
                    {
                        ReturnResult.Orientation.ResultYFlip = false;
                    }
                }
                else
                {
                    if ( tileChance.Direction.X != newDirection.X )
                    {
                        ReturnResult.Orientation.ResultXFlip = true;
                    }
                    else
                    {
                        ReturnResult.Orientation.ResultXFlip = false;
                    }
                    if ( tileChance.Direction.Y != newDirection.Y )
                    {
                        ReturnResult.Orientation.ResultYFlip = true;
                    }
                    else
                    {
                        ReturnResult.Orientation.ResultYFlip = false;
                    }
                }
                //randomly switch to the alternate orientation
                if ( VBMath.Rnd() >= 0.5F )
                {
                    if ( newDirection.X == 1 )
                    {
                        ReturnResult.Orientation.ResultXFlip = !ReturnResult.Orientation.ResultXFlip;
                    }
                    else
                    {
                        ReturnResult.Orientation.ResultYFlip = !ReturnResult.Orientation.ResultYFlip;
                    }
                }
            }

            return ReturnResult;
        }
        private void ToolPerformTile()
        {
            var PainterBrushNum = 0;
            var A = 0;

            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.TerrainCount - 1; PainterBrushNum++ )
            {
                PainterTerrainA = Painter.Terrains[PainterBrushNum];
                for ( A = 0; A <= PainterTerrainA.Tiles.TileCount - 1; A++ )
                {
                    PainterTexture = PainterTerrainA.Tiles.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
            }
            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.TransitionBrushCount - 1; PainterBrushNum++ )
            {
                PainterTerrainA = Painter.TransitionBrushes[PainterBrushNum].Terrain_Inner;
                PainterTerrainB = Painter.TransitionBrushes[PainterBrushNum].Terrain_Outer;
                for ( A = 0; A <= Painter.TransitionBrushes[PainterBrushNum].Tiles_Straight.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].Tiles_Straight.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.DirectionsOnSameSide(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.TransitionBrushes[PainterBrushNum].Tiles_Corner_In.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].Tiles_Corner_In.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.IdenticalTileDirections(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.TransitionBrushes[PainterBrushNum].Tiles_Corner_Out.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].Tiles_Corner_Out.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        OppositeDirection = PainterTexture.Direction;
                        OppositeDirection.FlipX();
                        OppositeDirection.FlipY();
                        TileUtil.RotateDirection(OppositeDirection, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.IdenticalTileDirections(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                    }
                }
            }

            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.CliffBrushCount - 1; PainterBrushNum++ )
            {
                PainterTerrainA = Painter.CliffBrushes[PainterBrushNum].Terrain_Inner;
                PainterTerrainB = Painter.CliffBrushes[PainterBrushNum].Terrain_Outer;
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Straight.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Straight.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.DirectionsOnSameSide(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_In.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_In.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.IdenticalTileDirections(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_Out.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.CliffBrushes[PainterBrushNum].Tiles_Corner_Out.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        OppositeDirection = PainterTexture.Direction;
                        OppositeDirection.FlipX();
                        OppositeDirection.FlipY();
                        TileUtil.RotateDirection(OppositeDirection, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.IdenticalTileDirections(VertexDirection, ResultDirection) )
                        {
                            TerrainCount[PainterTerrainA.Num]++;
                        }
                        else
                        {
                            TerrainCount[PainterTerrainB.Num]++;
                        }
                    }
                }
            }

            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.RoadBrushCount - 1; PainterBrushNum++ )
            {
                PainterTerrainA = Painter.RoadBrushes[PainterBrushNum].Terrain;
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_Corner_In.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_Corner_In.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_CrossIntersection.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_CrossIntersection.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_End.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_End.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_Straight.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_Straight.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_TIntersection.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_TIntersection.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TerrainCount[PainterTerrainA.Num]++;
                    }
                }
            }
        }
        protected void ToolPerformTile()
        {
            var PainterBrushNum = 0;
            var A = 0;

            for ( PainterBrushNum = 0; PainterBrushNum <= Painter.RoadBrushCount - 1; PainterBrushNum++ )
            {
                PainterRoad = Painter.RoadBrushes[PainterBrushNum].Road;
                PainterTerrain = Painter.RoadBrushes[PainterBrushNum].Terrain;
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_Corner_In.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_Corner_In.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.DirectionsOnSameSide(SideDirection, ResultDirection) )
                        {
                            RoadCount[PainterRoad.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_CrossIntersection.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_CrossIntersection.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        RoadCount[PainterRoad.Num]++;
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_End.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_End.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.IdenticalTileDirections(SideDirection, ResultDirection) )
                        {
                            RoadCount[PainterRoad.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_Straight.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_Straight.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( TileUtil.DirectionsAreInLine(SideDirection, ResultDirection) )
                        {
                            RoadCount[PainterRoad.Num]++;
                        }
                    }
                }
                for ( A = 0; A <= Painter.RoadBrushes[PainterBrushNum].Tile_TIntersection.TileCount - 1; A++ )
                {
                    PainterTexture = Painter.RoadBrushes[PainterBrushNum].Tile_TIntersection.Tiles[A];
                    if ( PainterTexture.TextureNum == Texture.TextureNum )
                    {
                        TileUtil.RotateDirection(PainterTexture.Direction, Texture.Orientation, ref ResultDirection);
                        if ( !TileUtil.DirectionsOnSameSide(SideDirection, ResultDirection) )
                        {
                            RoadCount[PainterRoad.Num]++;
                        }
                    }
                }
            }
        }