Exemplo n.º 1
0
        public override void ActionPerform()
        {
            var painterBrushNum = 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++)
            {
                var a = 0;
                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.º 2
0
        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]++;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        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].TerrainInner;
                PainterTerrainB = Painter.TransitionBrushes[PainterBrushNum].TerrainOuter;
                for (A = 0; A <= Painter.TransitionBrushes[PainterBrushNum].TilesStraight.TileCount - 1; A++)
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].TilesStraight.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].TilesCornerIn.TileCount - 1; A++)
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].TilesCornerIn.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].TilesCornerOut.TileCount - 1; A++)
                {
                    PainterTexture = Painter.TransitionBrushes[PainterBrushNum].TilesCornerOut.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]++;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Rotate(TileOrientation Orientation, Util.ObjectRotateMode 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(Unit);

            foreach (var tempLoopVar_Unit in Units)
            {
                Unit = tempLoopVar_Unit;
                Unit.Sectors.Clear();
                if (ObjectRotateMode == Util.ObjectRotateMode.All)
                {
                    Unit.Rotation = (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                         TileUtil.GetRotatedAngle(Orientation,
                                                                                  MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg).ToInt();
                    if (Unit.Rotation < 0)
                    {
                        Unit.Rotation += 360;
                    }
                }
                else if (ObjectRotateMode == ObjectRotateMode.Walls)
                {
                    if (Unit.TypeBase.Type == UnitType.PlayerStructure)
                    {
                        if (((StructureTypeBase)Unit.TypeBase).StructureType == StructureType.Wall)
                        {
                            Unit.Rotation = (MathUtil.AngleClamp(MathUtil.RadOf360Deg -
                                                                 TileUtil.GetRotatedAngle(Orientation,
                                                                                          MathUtil.AngleClamp(MathUtil.RadOf360Deg - Unit.Rotation * MathUtil.RadOf1Deg))) / MathUtil.RadOf1Deg)
                                            .ToInt();

                            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(Gateway);

            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();
            }
        }