Esempio n. 1
0
        public static double GetRotatedAngle(TileOrientation orientation, double angle)
        {
            Position.XY_dbl XY_dbl = default(Position.XY_dbl);

            XY_dbl = GetTileRotatedPos_dbl(orientation, new Position.XY_dbl((Math.Cos(angle) + 1.0D) / 2.0D, (Math.Sin(angle) + 1.0D) / 2.0D));
            XY_dbl.X = XY_dbl.X * 2.0D - 1.0D;
            XY_dbl.Y = XY_dbl.Y * 2.0D - 1.0D;
            return Math.Atan2(XY_dbl.Y, XY_dbl.X);
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        public static sXY_int GetRotatedPos(TileOrientation orientation, sXY_int pos, sXY_int limits)
        {
            sXY_int Result = new sXY_int();

            if ( orientation.SwitchedAxes )
            {
                if ( orientation.ResultXFlip )
                {
                    Result.X = limits.Y - pos.Y;
                }
                else
                {
                    Result.X = pos.Y;
                }
                if ( orientation.ResultYFlip )
                {
                    Result.Y = limits.X - pos.X;
                }
                else
                {
                    Result.Y = pos.X;
                }
            }
            else
            {
                if ( orientation.ResultXFlip )
                {
                    Result.X = limits.X - pos.X;
                }
                else
                {
                    Result.X = pos.X;
                }
                if ( orientation.ResultYFlip )
                {
                    Result.Y = limits.Y - pos.Y;
                }
                else
                {
                    Result.Y = pos.Y;
                }
            }

            return Result;
        }
Esempio n. 4
0
 public static void TileOrientation_To_OldOrientation(TileOrientation tileOrientation, ref byte OutputRotation, ref bool OutputFlipX)
 {
     if ( tileOrientation.SwitchedAxes )
     {
         if ( tileOrientation.ResultXFlip )
         {
             OutputRotation = (byte)1;
         }
         else
         {
             OutputRotation = (byte)3;
         }
         OutputFlipX = !(tileOrientation.ResultXFlip ^ tileOrientation.ResultYFlip);
     }
     else
     {
         if ( tileOrientation.ResultYFlip )
         {
             OutputRotation = (byte)2;
         }
         else
         {
             OutputRotation = (byte)0;
         }
         OutputFlipX = tileOrientation.ResultXFlip ^ tileOrientation.ResultYFlip;
     }
 }
Esempio n. 5
0
 public static void OldOrientation_To_TileOrientation(byte OldRotation, bool OldFlipX, bool OldFlipZ, TileOrientation Result)
 {
     if ( OldRotation == 0 )
     {
         Result.SwitchedAxes = false;
         Result.ResultXFlip = false;
         Result.ResultYFlip = false;
     }
     else if ( OldRotation == 1 )
     {
         Result.SwitchedAxes = true;
         Result.ResultXFlip = true;
         Result.ResultYFlip = false;
     }
     else if ( OldRotation == 2 )
     {
         Result.SwitchedAxes = false;
         Result.ResultXFlip = true;
         Result.ResultYFlip = true;
     }
     else if ( OldRotation == 3 )
     {
         Result.SwitchedAxes = true;
         Result.ResultXFlip = false;
         Result.ResultYFlip = true;
     }
     if ( OldFlipX )
     {
         if ( Result.SwitchedAxes )
         {
             Result.ResultYFlip = !Result.ResultYFlip;
         }
         else
         {
             Result.ResultXFlip = !Result.ResultXFlip;
         }
     }
     if ( OldFlipZ )
     {
         if ( Result.SwitchedAxes )
         {
             Result.ResultXFlip = !Result.ResultXFlip;
         }
         else
         {
             Result.ResultYFlip = !Result.ResultYFlip;
         }
     }
 }
Esempio n. 6
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();
     }
 }
Esempio n. 7
0
        public static sXY_sng GetTileRotatedPos_sng(TileOrientation tileOrientation, sXY_sng pos)
        {
            sXY_sng ReturnResult = new sXY_sng();

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.Y = pos.Y;
                }
            }

            return ReturnResult;
        }
Esempio n. 8
0
        public static void GetTileRotatedTexCoords(TileOrientation tileOrientation, sXY_sng coordA, sXY_sng coordB, sXY_sng coordC,
            sXY_sng coordD)
        {
            TileOrientation ReverseOrientation = new TileOrientation();

            ReverseOrientation = tileOrientation;
            ReverseOrientation.Reverse();

            if ( ReverseOrientation.SwitchedAxes )
            {
                if ( ReverseOrientation.ResultXFlip )
                {
                    coordA.X = 1.0F;
                    coordB.X = 1.0F;
                    coordC.X = 0.0F;
                    coordD.X = 0.0F;
                }
                else
                {
                    coordA.X = 0.0F;
                    coordB.X = 0.0F;
                    coordC.X = 1.0F;
                    coordD.X = 1.0F;
                }
                if ( ReverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1.0F;
                    coordB.Y = 0.0F;
                    coordC.Y = 1.0F;
                    coordD.Y = 0.0F;
                }
                else
                {
                    coordA.Y = 0.0F;
                    coordB.Y = 1.0F;
                    coordC.Y = 0.0F;
                    coordD.Y = 1.0F;
                }
            }
            else
            {
                if ( ReverseOrientation.ResultXFlip )
                {
                    coordA.X = 1.0F;
                    coordB.X = 0.0F;
                    coordC.X = 1.0F;
                    coordD.X = 0.0F;
                }
                else
                {
                    coordA.X = 0.0F;
                    coordB.X = 1.0F;
                    coordC.X = 0.0F;
                    coordD.X = 1.0F;
                }
                if ( ReverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1.0F;
                    coordB.Y = 1.0F;
                    coordC.Y = 0.0F;
                    coordD.Y = 0.0F;
                }
                else
                {
                    coordA.Y = 0.0F;
                    coordB.Y = 0.0F;
                    coordC.Y = 1.0F;
                    coordD.Y = 1.0F;
                }
            }
        }
Esempio n. 9
0
        public static Position.XY_dbl GetTileRotatedPos_dbl(TileOrientation tileOrientation, Position.XY_dbl pos)
        {
            Position.XY_dbl ReturnResult = default(Position.XY_dbl);

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0D - pos.Y;
                }
                else
                {
                    ReturnResult.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0D - pos.X;
                }
                else
                {
                    ReturnResult.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0D - pos.X;
                }
                else
                {
                    ReturnResult.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0D - pos.Y;
                }
                else
                {
                    ReturnResult.Y = pos.Y;
                }
            }

            return ReturnResult;
        }
Esempio n. 10
0
        public static sXY_int GetTileRotatedOffset(TileOrientation tileOrientation, sXY_int pos)
        {
            sXY_int Result = new sXY_int();

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    Result.X = App.TerrainGridSpacing - pos.Y;
                }
                else
                {
                    Result.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    Result.Y = App.TerrainGridSpacing - pos.X;
                }
                else
                {
                    Result.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    Result.X = App.TerrainGridSpacing - pos.X;
                }
                else
                {
                    Result.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    Result.Y = App.TerrainGridSpacing - pos.Y;
                }
                else
                {
                    Result.Y = pos.Y;
                }
            }

            return Result;
        }
Esempio n. 11
0
        public static void GetTileRotatedTexCoords(TileOrientation tileOrientation, ref XYDouble coordA, ref XYDouble coordB,
            ref XYDouble coordC, ref XYDouble coordD)
        {
            var reverseOrientation = new TileOrientation();

            reverseOrientation = tileOrientation;
            reverseOrientation.Reverse();

            if ( reverseOrientation.SwitchedAxes )
            {
                if ( reverseOrientation.ResultXFlip )
                {
                    coordA.X = 1f;
                    coordB.X = 1f;
                    coordC.X = 0f;
                    coordD.X = 0f;
                }
                else
                {
                    coordA.X = 0f;
                    coordB.X = 0f;
                    coordC.X = 1f;
                    coordD.X = 1f;
                }
                if ( reverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1f;
                    coordB.Y = 0f;
                    coordC.Y = 1f;
                    coordD.Y = 0f;
                }
                else
                {
                    coordA.Y = 0f;
                    coordB.Y = 1f;
                    coordC.Y = 0f;
                    coordD.Y = 1f;
                }
            }
            else
            {
                if ( reverseOrientation.ResultXFlip )
                {
                    coordA.X = 1f;
                    coordB.X = 0f;
                    coordC.X = 1f;
                    coordD.X = 0f;
                }
                else
                {
                    coordA.X = 0f;
                    coordB.X = 1F;
                    coordC.X = 0f;
                    coordD.X = 1f;
                }
                if ( reverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1f;
                    coordB.Y = 1f;
                    coordC.Y = 0f;
                    coordD.Y = 0f;
                }
                else
                {
                    coordA.Y = 0f;
                    coordB.Y = 0f;
                    coordC.Y = 1f;
                    coordD.Y = 1f;
                }
            }
        }
Esempio n. 12
0
        public static XYDouble GetTileRotatedPos_sng(TileOrientation tileOrientation, XYDouble pos)
        {
            var ReturnResult = new XYDouble();

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.Y = pos.Y;
                }
            }

            return ReturnResult;
        }
Esempio n. 13
0
        public static XYInt GetTileRotatedOffset(TileOrientation tileOrientation, XYInt pos)
        {
            var Result = new XYInt();

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    Result.X = Constants.TerrainGridSpacing - pos.Y;
                }
                else
                {
                    Result.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    Result.Y = Constants.TerrainGridSpacing - pos.X;
                }
                else
                {
                    Result.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    Result.X = Constants.TerrainGridSpacing - pos.X;
                }
                else
                {
                    Result.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    Result.Y = Constants.TerrainGridSpacing - pos.Y;
                }
                else
                {
                    Result.Y = pos.Y;
                }
            }

            return Result;
        }