예제 #1
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();
            }
        }