Ejemplo n.º 1
0
        public clsMap(clsMap MapToCopy, sXY_int Offset, sXY_int Area)
        {
            frmMainLink = new ConnectedListLink<clsMap, frmMain>(this);
            Gateways = new ConnectedList<clsGateway, clsMap>(this);

            int EndX = 0;
            int EndY = 0;
            int X = 0;
            int Y = 0;

            Initialize();

            //make some map data for selection

            EndX = Math.Min(MapToCopy.Terrain.TileSize.X - Offset.X, Area.X);
            EndY = Math.Min(MapToCopy.Terrain.TileSize.Y - Offset.Y, Area.Y);

            Terrain = new clsTerrain(Area);

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Texture.TextureNum = -1;
                }
            }

            for ( Y = 0; Y <= EndY; Y++ )
            {
                for ( X = 0; X <= EndX; X++ )
                {
                    Terrain.Vertices[X, Y].Height = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height;
                    Terrain.Vertices[X, Y].Terrain = MapToCopy.Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain;
                }
            }
            for ( Y = 0; Y <= EndY - 1; Y++ )
            {
                for ( X = 0; X <= EndX - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Copy(MapToCopy.Terrain.Tiles[Offset.X + X, Offset.Y + Y]);
                }
            }
            for ( Y = 0; Y <= EndY; Y++ )
            {
                for ( X = 0; X <= EndX - 1; X++ )
                {
                    Terrain.SideH[X, Y].Road = MapToCopy.Terrain.SideH[Offset.X + X, Offset.Y + Y].Road;
                }
            }
            for ( Y = 0; Y <= EndY - 1; Y++ )
            {
                for ( X = 0; X <= EndX; X++ )
                {
                    Terrain.SideV[X, Y].Road = MapToCopy.Terrain.SideV[Offset.X + X, Offset.Y + Y].Road;
                }
            }

            SectorCount.X = (int)(Math.Ceiling((double)(Area.X / Constants.SectorTileSize)));
            SectorCount.Y = (int)(Math.Ceiling((double)(Area.Y / Constants.SectorTileSize)));
            Sectors = new clsSector[SectorCount.X, SectorCount.Y];
            for ( Y = 0; Y <= SectorCount.Y - 1; Y++ )
            {
                for ( X = 0; X <= SectorCount.X - 1; X++ )
                {
                    Sectors[X, Y] = new clsSector(new sXY_int(X, Y));
                }
            }

            sXY_int PosDif = new sXY_int();
            clsUnitAdd NewUnitAdd = new clsUnitAdd();
            NewUnitAdd.Map = this;
            clsUnit NewUnit = default(clsUnit);

            clsGateway Gateway = default(clsGateway);
            foreach ( clsGateway tempLoopVar_Gateway in MapToCopy.Gateways )
            {
                Gateway = tempLoopVar_Gateway;
                GatewayCreate(new sXY_int(Gateway.PosA.X - Offset.X, Gateway.PosA.Y - Offset.Y),
                    new sXY_int(Gateway.PosB.X - Offset.X, Gateway.PosB.Y - Offset.Y));
            }

            PosDif.X = - Offset.X * App.TerrainGridSpacing;
            PosDif.Y = - Offset.Y * App.TerrainGridSpacing;
            clsUnit Unit = default(clsUnit);
            sXY_int NewPos = new sXY_int();
            foreach ( clsUnit tempLoopVar_Unit in MapToCopy.Units )
            {
                Unit = tempLoopVar_Unit;
                NewPos = Unit.Pos.Horizontal + PosDif;
                if ( PosIsOnMap(NewPos) )
                {
                    NewUnit = new clsUnit(Unit, this);
                    NewUnit.Pos.Horizontal = NewPos;
                    NewUnitAdd.NewUnit = NewUnit;
                    NewUnitAdd.Label = Unit.Label;
                    NewUnitAdd.Perform();
                }
            }
        }
Ejemplo n.º 2
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.º 3
0
        protected void TerrainBlank(sXY_int TileSize)
        {
            int X = 0;
            int Y = 0;

            Terrain = new clsTerrain(TileSize);
            SectorCount.X = (int)(Math.Ceiling((double)(Terrain.TileSize.X / Constants.SectorTileSize)));
            SectorCount.Y = (int)(Math.Ceiling((double)(Terrain.TileSize.Y / Constants.SectorTileSize)));
            Sectors = new clsSector[SectorCount.X, SectorCount.Y];
            for ( Y = 0; Y <= SectorCount.Y - 1; Y++ )
            {
                for ( X = 0; X <= SectorCount.X - 1; X++ )
                {
                    Sectors[X, Y] = new clsSector(new sXY_int(X, Y));
                }
            }
        }
Ejemplo n.º 4
0
        public void TerrainResize(sXY_int Offset, sXY_int Size)
        {
            int StartX = 0;
            int StartY = 0;
            int EndX = 0;
            int EndY = 0;
            int X = 0;
            int Y = 0;
            clsTerrain NewTerrain = new clsTerrain(Size);

            StartX = Math.Max(0 - Offset.X, 0);
            StartY = Math.Max(0 - Offset.Y, 0);
            EndX = Math.Min(Terrain.TileSize.X - Offset.X, Size.X);
            EndY = Math.Min(Terrain.TileSize.Y - Offset.Y, Size.Y);

            for ( Y = 0; Y <= NewTerrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= NewTerrain.TileSize.X - 1; X++ )
                {
                    NewTerrain.Tiles[X, Y].Texture.TextureNum = -1;
                }
            }

            for ( Y = StartY; Y <= EndY; Y++ )
            {
                for ( X = StartX; X <= EndX; X++ )
                {
                    NewTerrain.Vertices[X, Y].Height = Terrain.Vertices[Offset.X + X, Offset.Y + Y].Height;
                    NewTerrain.Vertices[X, Y].Terrain = Terrain.Vertices[Offset.X + X, Offset.Y + Y].Terrain;
                }
            }
            for ( Y = StartY; Y <= EndY - 1; Y++ )
            {
                for ( X = StartX; X <= EndX - 1; X++ )
                {
                    NewTerrain.Tiles[X, Y].Copy(Terrain.Tiles[Offset.X + X, Offset.Y + Y]);
                }
            }
            for ( Y = StartY; Y <= EndY; Y++ )
            {
                for ( X = StartX; X <= EndX - 1; X++ )
                {
                    NewTerrain.SideH[X, Y].Road = Terrain.SideH[Offset.X + X, Offset.Y + Y].Road;
                }
            }
            for ( Y = StartY; Y <= EndY - 1; Y++ )
            {
                for ( X = StartX; X <= EndX; X++ )
                {
                    NewTerrain.SideV[X, Y].Road = Terrain.SideV[Offset.X + X, Offset.Y + Y].Road;
                }
            }

            int PosDifX = 0;
            int PosDifZ = 0;
            clsUnit Unit = default(clsUnit);
            clsGateway Gateway = default(clsGateway);

            PosDifX = - Offset.X * App.TerrainGridSpacing;
            PosDifZ = - Offset.Y * App.TerrainGridSpacing;
            foreach ( clsUnit tempLoopVar_Unit in Units )
            {
                Unit = tempLoopVar_Unit;
                Unit.Pos.Horizontal.X += PosDifX;
                Unit.Pos.Horizontal.Y += PosDifZ;
            }
            foreach ( clsGateway tempLoopVar_Gateway in Gateways )
            {
                Gateway = tempLoopVar_Gateway;
                Gateway.PosA.X -= Offset.X;
                Gateway.PosA.Y -= Offset.Y;
                Gateway.PosB.X -= Offset.X;
                Gateway.PosB.Y -= Offset.Y;
            }

            sXY_int ZeroPos = new sXY_int(0, 0);

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

            Terrain = NewTerrain;

            foreach ( clsGateway tempLoopVar_Gateway in Gateways.GetItemsAsSimpleList() )
            {
                Gateway = tempLoopVar_Gateway;
                if ( Gateway.IsOffMap() )
                {
                    Gateway.Deallocate();
                }
            }

            sXY_int PosOffset = new sXY_int(Offset.X * App.TerrainGridSpacing, Offset.Y * App.TerrainGridSpacing);

            clsScriptPosition ScriptPosition = default(clsScriptPosition);
            foreach ( clsScriptPosition tempLoopVar_ScriptPosition in ScriptPositions.GetItemsAsSimpleList() )
            {
                ScriptPosition = tempLoopVar_ScriptPosition;
                ScriptPosition.MapResizing(PosOffset);
            }

            clsScriptArea ScriptArea = default(clsScriptArea);
            foreach ( clsScriptArea tempLoopVar_ScriptArea in ScriptAreas.GetItemsAsSimpleList() )
            {
                ScriptArea = tempLoopVar_ScriptArea;
                ScriptArea.MapResizing(PosOffset);
            }

            if ( _ReadyForUserInput )
            {
                CancelUserInput();
                InitializeUserInput();
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
        public void TerrainBlank(XYInt TileSize)
        {
            var X = 0;
            var Y = 0;

            Terrain = new clsTerrain(TileSize);
            SectorCount.X = (int)(Math.Ceiling(((double)Terrain.TileSize.X / Constants.SectorTileSize)));
            SectorCount.Y = (int)(Math.Ceiling(((double)Terrain.TileSize.Y / Constants.SectorTileSize)));
            Sectors = new clsSector[SectorCount.X, SectorCount.Y];
            for ( Y = 0; Y <= SectorCount.Y - 1; Y++ )
            {
                for ( X = 0; X <= SectorCount.X - 1; X++ )
                {
                    Sectors[X, Y] = new clsSector(new XYInt(X, Y));
                }
            }
        }