Ejemplo n.º 1
0
 public static bool DirectionsOnSameSide(TileDirection DirectionA, TileDirection DirectionB)
 {
     if ( DirectionA.X == 0 )
     {
         if ( DirectionB.X == 0 )
         {
             return true;
         }
     }
     if ( DirectionA.X == 2 )
     {
         if ( DirectionB.X == 2 )
         {
             return true;
         }
     }
     if ( DirectionA.Y == 0 )
     {
         if ( DirectionB.Y == 0 )
         {
             return true;
         }
     }
     if ( DirectionA.Y == 2 )
     {
         if ( DirectionB.Y == 2 )
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
        public void Tile_Add(int TileNum, TileDirection TileOutwardOrientation, UInt32 Chance)
        {
            Array.Resize(ref Tiles, TileCount + 1);
            Tiles[TileCount].TextureNum = TileNum;
            Tiles[TileCount].Direction = TileOutwardOrientation;
            Tiles[TileCount].Chance = Chance;
            TileCount++;

            TileChanceTotal += Convert.ToInt32(Chance);
        }
Ejemplo n.º 3
0
 public void Copy(Tile TileToCopy)
 {
     Texture = TileToCopy.Texture;
     Tri = TileToCopy.Tri;
     TriTopLeftIsCliff = TileToCopy.TriTopLeftIsCliff;
     TriTopRightIsCliff = TileToCopy.TriTopRightIsCliff;
     TriBottomLeftIsCliff = TileToCopy.TriBottomLeftIsCliff;
     TriBottomRightIsCliff = TileToCopy.TriBottomRightIsCliff;
     Terrain_IsCliff = TileToCopy.Terrain_IsCliff;
     DownSide = TileToCopy.DownSide;
 }
Ejemplo n.º 4
0
 public static bool DirectionsAreInLine(TileDirection DirectionA, TileDirection DirectionB)
 {
     if ( DirectionA.X == DirectionB.X )
     {
         return true;
     }
     if ( DirectionA.Y == DirectionB.Y )
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
 public void TriCliffAddDirection(TileDirection Direction)
 {
     if ( Direction.X == 0 )
     {
         if ( Direction.Y == 0 )
         {
             TriTopLeftIsCliff = true;
         }
         else if ( Direction.Y == 2 )
         {
             TriBottomLeftIsCliff = true;
         }
         else
         {
             Debugger.Break();
         }
     }
     else if ( Direction.X == 2 )
     {
         if ( Direction.Y == 0 )
         {
             TriTopRightIsCliff = true;
         }
         else if ( Direction.Y == 2 )
         {
             TriBottomRightIsCliff = true;
         }
         else
         {
             Debugger.Break();
         }
     }
     else
     {
         Debugger.Break();
     }
 }
Ejemplo n.º 6
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);
            }
Ejemplo n.º 7
0
        public void Rotate(TileOrientation Orientation, enumObjectRotateMode ObjectRotateMode)
        {
            var X = 0;
            var Y = 0;
            var Pos = new XYInt(0, 0);
            var RotatedPos = new XYInt();
            var NewTerrainPosA = TileUtil.GetRotatedPos(Orientation, new XYInt(0, 0), Terrain.TileSize);
            var NewTerrainPosB = TileUtil.GetRotatedPos(Orientation, Terrain.TileSize, Terrain.TileSize);
            var VertexLimits = new XYInt(Math.Max(NewTerrainPosA.X, NewTerrainPosB.X), Math.Max(NewTerrainPosA.Y, NewTerrainPosB.Y));
            var NewTerrain = new clsTerrain(VertexLimits);
            var NewTileLimits = new XYInt(NewTerrain.TileSize.X - 1, NewTerrain.TileSize.Y - 1);
            var NewSideHLimits = new XYInt(NewTerrain.TileSize.X - 1, NewTerrain.TileSize.Y);
            var NewSideVLimits = new XYInt(NewTerrain.TileSize.X, NewTerrain.TileSize.Y - 1);
            var OldTileLimits = new XYInt(Terrain.TileSize.X - 1, Terrain.TileSize.Y - 1);
            var OldPosLimits = new XYInt(Terrain.TileSize.X * Constants.TerrainGridSpacing, Terrain.TileSize.Y * Constants.TerrainGridSpacing);
            var ReverseOrientation = new TileOrientation();
            var TriDirection = new TileDirection();

            ReverseOrientation = Orientation;
            ReverseOrientation.Reverse();

            for ( Y = 0; Y <= NewTerrain.TileSize.Y; Y++ )
            {
                Pos.Y = Y;
                for ( X = 0; X <= NewTerrain.TileSize.X; X++ )
                {
                    Pos.X = X;
                    RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, VertexLimits);
                    NewTerrain.Vertices[X, Y].Height = Terrain.Vertices[RotatedPos.X, RotatedPos.Y].Height;
                    NewTerrain.Vertices[X, Y].Terrain = Terrain.Vertices[RotatedPos.X, RotatedPos.Y].Terrain;
                }
            }
            for ( Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++ )
            {
                Pos.Y = Y;
                for ( X = 0; X <= NewTerrain.TileSize.X - 1; X++ )
                {
                    Pos.X = X;
                    RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewTileLimits);
                    NewTerrain.Tiles[X, Y].Texture = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Texture;
                    NewTerrain.Tiles[X, Y].Texture.Orientation = NewTerrain.Tiles[X, Y].Texture.Orientation.GetRotated(Orientation);
                    NewTerrain.Tiles[X, Y].DownSide = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].DownSide;
                    NewTerrain.Tiles[X, Y].DownSide = NewTerrain.Tiles[X, Y].DownSide.GetRotated(Orientation);
                    if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Tri )
                    {
                        TriDirection = TileUtil.TopLeft;
                    }
                    else
                    {
                        TriDirection = TileUtil.TopRight;
                    }
                    TriDirection = TriDirection.GetRotated(Orientation);
                    NewTerrain.Tiles[X, Y].Tri =
                        Convert.ToBoolean(TileUtil.IdenticalTileDirections(TriDirection, TileUtil.TopLeft) ||
                                          TileUtil.IdenticalTileDirections(TriDirection, TileUtil.BottomRight));
                    if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Tri )
                    {
                        if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriTopLeftIsCliff )
                        {
                            TileUtil.RotateDirection(TileUtil.TopLeft, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                        if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriBottomRightIsCliff )
                        {
                            TileUtil.RotateDirection(TileUtil.BottomRight, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                    }
                    else
                    {
                        if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriTopRightIsCliff )
                        {
                            TileUtil.RotateDirection(TileUtil.TopRight, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                        if ( Terrain.Tiles[RotatedPos.X, RotatedPos.Y].TriBottomLeftIsCliff )
                        {
                            TileUtil.RotateDirection(TileUtil.BottomLeft, Orientation, ref TriDirection);
                            NewTerrain.Tiles[X, Y].TriCliffAddDirection(TriDirection);
                        }
                    }
                    NewTerrain.Tiles[X, Y].Terrain_IsCliff = Terrain.Tiles[RotatedPos.X, RotatedPos.Y].Terrain_IsCliff;
                }
            }
            if ( Orientation.SwitchedAxes )
            {
                for ( Y = 0; Y <= NewTerrain.TileSize.Y; Y++ )
                {
                    Pos.Y = Y;
                    for ( X = 0; X <= NewTerrain.TileSize.X - 1; X++ )
                    {
                        Pos.X = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideHLimits);
                        NewTerrain.SideH[X, Y].Road = Terrain.SideV[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
                for ( Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++ )
                {
                    Pos.Y = Y;
                    for ( X = 0; X <= NewTerrain.TileSize.X; X++ )
                    {
                        Pos.X = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideVLimits);
                        NewTerrain.SideV[X, Y].Road = Terrain.SideH[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
            }
            else
            {
                for ( Y = 0; Y <= NewTerrain.TileSize.Y; Y++ )
                {
                    Pos.Y = Y;
                    for ( X = 0; X <= NewTerrain.TileSize.X - 1; X++ )
                    {
                        Pos.X = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideHLimits);
                        NewTerrain.SideH[X, Y].Road = Terrain.SideH[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
                for ( Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++ )
                {
                    Pos.Y = Y;
                    for ( X = 0; X <= NewTerrain.TileSize.X; X++ )
                    {
                        Pos.X = X;
                        RotatedPos = TileUtil.GetRotatedPos(ReverseOrientation, Pos, NewSideVLimits);
                        NewTerrain.SideV[X, Y].Road = Terrain.SideV[RotatedPos.X, RotatedPos.Y].Road;
                    }
                }
            }

            var Unit = default(clsUnit);
            foreach ( var tempLoopVar_Unit in Units )
            {
                Unit = tempLoopVar_Unit;
                Unit.Sectors.Clear();
                if ( ObjectRotateMode == enumObjectRotateMode.All )
                {
                    Unit.Rotation =
                        (int)
                            (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                 TileUtil.GetRotatedAngle(Orientation,
                                                     MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg);
                    if ( Unit.Rotation < 0 )
                    {
                        Unit.Rotation += 360;
                    }
                }
                else if ( ObjectRotateMode == enumObjectRotateMode.Walls )
                {
                    if ( Unit.TypeBase.Type == UnitType.PlayerStructure )
                    {
                        if ( ((StructureTypeBase)Unit.TypeBase).StructureType == StructureTypeBase.enumStructureType.Wall )
                        {
                            Unit.Rotation =
                                (int)
                                    (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                         TileUtil.GetRotatedAngle(Orientation,
                                                             MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg);
                            if ( Unit.Rotation < 0 )
                            {
                                Unit.Rotation += 360;
                            }
                            //If Unit.Rotation = 180 Then
                            //    Unit.Rotation = 0
                            //ElseIf Unit.Rotation = 270 Then
                            //    Unit.Rotation = 90
                            //End If
                        }
                    }
                }
                Unit.Pos.Horizontal = TileUtil.GetRotatedPos(Orientation, Unit.Pos.Horizontal, OldPosLimits);
            }

            var ZeroPos = new XYInt(0, 0);

            var Position = 0;
            foreach ( var tempLoopVar_Unit in Units.GetItemsAsSimpleList() )
            {
                Unit = tempLoopVar_Unit;
                if ( !App.PosIsWithinTileArea(Unit.Pos.Horizontal, ZeroPos, NewTerrain.TileSize) )
                {
                    Position = Unit.MapLink.ArrayPosition;
                    UnitRemove(Position);
                }
            }

            Terrain = NewTerrain;

            var Gateway = default(clsGateway);
            foreach ( var tempLoopVar_Gateway in Gateways.GetItemsAsSimpleClassList() )
            {
                Gateway = tempLoopVar_Gateway;
                GatewayCreate(TileUtil.GetRotatedPos(Orientation, Gateway.PosA, OldTileLimits),
                    TileUtil.GetRotatedPos(Orientation, Gateway.PosB, OldTileLimits));
                Gateway.Deallocate();
            }

            if ( _ReadyForUserInput )
            {
                CancelUserInput();
                InitializeUserInput();
            }
        }
        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);
        }
Ejemplo n.º 9
0
 public static void RotateDirection(TileDirection initialDirection, TileOrientation orientation, ref TileDirection ResultDirection)
 {
     ResultDirection = initialDirection;
     if ( orientation.SwitchedAxes )
     {
         ResultDirection.SwitchAxes();
     }
     if ( orientation.ResultXFlip )
     {
         ResultDirection.FlipX();
     }
     if ( orientation.ResultYFlip )
     {
         ResultDirection.FlipY();
     }
 }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
 public static bool IdenticalTileDirections(TileDirection TileOrientationA, TileDirection TileOrientationB)
 {
     return TileOrientationA.X == TileOrientationB.X & TileOrientationA.Y == TileOrientationB.Y;
 }
        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]++;
                    }
                }
            }
        }
        public override void ActionPerform()
        {
            var A = 0;

            Terrain = Map.Terrain;

            Painter = Map.Painter;
            TerrainCount = new int[Painter.TerrainCount];

            if ( PosNum.Y > 0 )
            {
                if ( PosNum.X > 0 )
                {
                    VertexDirection = TileUtil.BottomRight;
                    Tile = Terrain.Tiles[PosNum.X - 1, PosNum.Y - 1];
                    Texture = Tile.Texture;
                    ToolPerformTile();
                }
                if ( PosNum.X < Terrain.TileSize.X )
                {
                    VertexDirection = TileUtil.BottomLeft;
                    Tile = Terrain.Tiles[PosNum.X, PosNum.Y - 1];
                    Texture = Tile.Texture;
                    ToolPerformTile();
                }
            }
            if ( PosNum.Y < Terrain.TileSize.Y )
            {
                if ( PosNum.X > 0 )
                {
                    VertexDirection = TileUtil.TopRight;
                    Tile = Terrain.Tiles[PosNum.X - 1, PosNum.Y];
                    Texture = Tile.Texture;
                    ToolPerformTile();
                }
                if ( PosNum.X < Terrain.TileSize.X )
                {
                    VertexDirection = TileUtil.TopLeft;
                    Tile = Terrain.Tiles[PosNum.X, PosNum.Y];
                    Texture = Tile.Texture;
                    ToolPerformTile();
                }
            }

            BestNum = -1;
            BestCount = 0;
            for ( A = 0; A <= Painter.TerrainCount - 1; A++ )
            {
                if ( TerrainCount[A] > BestCount )
                {
                    BestNum = A;
                    BestCount = TerrainCount[A];
                }
            }
            if ( BestCount > 0 )
            {
                Terrain.Vertices[PosNum.X, PosNum.Y].Terrain = Painter.Terrains[BestNum];
            }
            else
            {
                Terrain.Vertices[PosNum.X, PosNum.Y].Terrain = null;
            }

            Map.SectorTerrainUndoChanges.VertexChanged(PosNum);
        }