Esempio n. 1
0
        public void Expand_One_Tile(BooleanMap Source)
        {
            var X = 0;
            var Y = 0;

            SizeCopy(Source);
            for ( Y = 0; Y <= ValueData.Size.Y - 1; Y++ )
            {
                for ( X = 0; X <= Source.ValueData.Size.X - 1; X++ )
                {
                    if ( Source.ValueData.Value[Y, X] )
                    {
                        ValueData.Value[Y, X] = true;
                        if ( Y > 0 )
                        {
                            if ( X > 0 )
                            {
                                ValueData.Value[Y - 1, X - 1] = true;
                            }
                            ValueData.Value[Y - 1, X] = true;
                            if ( X < Source.ValueData.Size.X - 1 )
                            {
                                ValueData.Value[Y - 1, X + 1] = true;
                            }
                        }
                        if ( X > 0 )
                        {
                            ValueData.Value[Y, X - 1] = true;
                        }
                        ValueData.Value[Y, X] = true;
                        if ( X < ValueData.Size.X - 1 )
                        {
                            ValueData.Value[Y, X + 1] = true;
                        }
                        if ( Y < ValueData.Size.Y - 1 )
                        {
                            if ( X > 0 )
                            {
                                ValueData.Value[Y + 1, X - 1] = true;
                            }
                            ValueData.Value[Y + 1, X] = true;
                            if ( X < ValueData.Size.X - 1 )
                            {
                                ValueData.Value[Y + 1, X + 1] = true;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void Copy(BooleanMap Source)
        {
            var X = 0;
            var Y = 0;

            SizeCopy(Source);
            for ( Y = 0; Y <= Source.ValueData.Size.Y - 1; Y++ )
            {
                for ( X = 0; X <= Source.ValueData.Size.X - 1; X++ )
                {
                    ValueData.Value[Y, X] = Source.ValueData.Value[Y, X];
                }
            }
        }
Esempio n. 3
0
        public void Combine(BooleanMap Source, BooleanMap Insert)
        {
            var X = 0;
            var Y = 0;

            SizeCopy(Source);
            for ( Y = 0; Y <= Source.ValueData.Size.Y - 1; Y++ )
            {
                for ( X = 0; X <= Source.ValueData.Size.X - 1; X++ )
                {
                    if ( Insert.ValueData.Value[Y, X] )
                    {
                        ValueData.Value[Y, X] = true;
                    }
                    else
                    {
                        ValueData.Value[Y, X] = Source.ValueData.Value[Y, X];
                    }
                }
            }
        }
Esempio n. 4
0
        public void MapTexturer(ref sLayerList LayerList)
        {
            var X = 0;
            var Y = 0;
            var A = 0;
            Terrain[,] TerrainType = null;
            float[,] Slope = null;
            var tmpTerrain = default(Terrain);
            var bmA = new BooleanMap();
            var bmB = new BooleanMap();
            var LayerNum = 0;
            var LayerResult = new BooleanMap[LayerList.LayerCount];
            double BestSlope = 0;
            double CurrentSlope = 0;
            var AllowSlope = default(bool);
            var Pos = new XYInt();

            TerrainType = new Terrain[Terrain.TileSize.X + 1, Terrain.TileSize.Y + 1];
            Slope = new float[Terrain.TileSize.X, Terrain.TileSize.Y];
            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    //get slope
                    BestSlope = 0.0D;

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Slope[X, Y] = (float)BestSlope;
                }
            }
            for ( LayerNum = 0; LayerNum <= LayerList.LayerCount - 1; LayerNum++ )
            {
                tmpTerrain = LayerList.Layers[LayerNum].Terrain;
                if ( tmpTerrain != null )
                {
                    //do other layer constraints
                    LayerResult[LayerNum] = new BooleanMap();
                    LayerResult[LayerNum].Copy(LayerList.Layers[LayerNum].Terrainmap);
                    if ( LayerList.Layers[LayerNum].WithinLayer >= 0 )
                    {
                        if ( LayerList.Layers[LayerNum].WithinLayer < LayerNum )
                        {
                            bmA.Within(LayerResult[LayerNum], LayerResult[LayerList.Layers[LayerNum].WithinLayer]);
                            LayerResult[LayerNum].ValueData = bmA.ValueData;
                            bmA.ValueData = new BooleanMapDataValue();
                        }
                    }
                    for ( A = 0; A <= LayerNum - 1; A++ )
                    {
                        if ( LayerList.Layers[LayerNum].AvoidLayers[A] )
                        {
                            bmA.Expand_One_Tile(LayerResult[A]);
                            bmB.Remove(LayerResult[LayerNum], bmA);
                            LayerResult[LayerNum].ValueData = bmB.ValueData;
                            bmB.ValueData = new BooleanMapDataValue();
                        }
                    }
                    //do height and slope constraints
                    for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X; X++ )
                        {
                            if ( LayerResult[LayerNum].ValueData.Value[Y, X] )
                            {
                                if ( Terrain.Vertices[X, Y].Height < LayerList.Layers[LayerNum].HeightMin
                                     || Terrain.Vertices[X, Y].Height > LayerList.Layers[LayerNum].HeightMax )
                                {
                                    LayerResult[LayerNum].ValueData.Value[Y, X] = false;
                                }
                                if ( LayerResult[LayerNum].ValueData.Value[Y, X] )
                                {
                                    AllowSlope = true;
                                    if ( X > 0 )
                                    {
                                        if ( Y > 0 )
                                        {
                                            if ( Slope[X - 1, Y - 1] < LayerList.Layers[LayerNum].SlopeMin
                                                 || Slope[X - 1, Y - 1] > LayerList.Layers[LayerNum].SlopeMax )
                                            {
                                                AllowSlope = false;
                                            }
                                        }
                                        if ( Y < Terrain.TileSize.Y )
                                        {
                                            if ( Slope[X - 1, Y] < LayerList.Layers[LayerNum].SlopeMin
                                                 || Slope[X - 1, Y] > LayerList.Layers[LayerNum].SlopeMax )
                                            {
                                                AllowSlope = false;
                                            }
                                        }
                                    }
                                    if ( X < Terrain.TileSize.X )
                                    {
                                        if ( Y > 0 )
                                        {
                                            if ( Slope[X, Y - 1] < LayerList.Layers[LayerNum].SlopeMin
                                                 || Slope[X, Y - 1] > LayerList.Layers[LayerNum].SlopeMax )
                                            {
                                                AllowSlope = false;
                                            }
                                        }
                                        if ( Y < Terrain.TileSize.Y )
                                        {
                                            if ( Slope[X, Y] < LayerList.Layers[LayerNum].SlopeMin
                                                 || Slope[X, Y] > LayerList.Layers[LayerNum].SlopeMax )
                                            {
                                                AllowSlope = false;
                                            }
                                        }
                                    }
                                    if ( !AllowSlope )
                                    {
                                        LayerResult[LayerNum].ValueData.Value[Y, X] = false;
                                    }
                                }
                            }
                        }
                    }

                    LayerResult[LayerNum].Remove_Diagonals();

                    for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X; X++ )
                        {
                            if ( LayerResult[LayerNum].ValueData.Value[Y, X] )
                            {
                                TerrainType[X, Y] = tmpTerrain;
                            }
                        }
                    }
                }
            }

            //set vertex terrain by terrain map
            for ( Y = 0; Y <= Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X; X++ )
                {
                    if ( TerrainType[X, Y] != null )
                    {
                        Terrain.Vertices[X, Y].Terrain = TerrainType[X, Y];
                    }
                }
            }
            AutoTextureChanges.SetAllChanged();
            UpdateAutoTextures();
        }
Esempio n. 5
0
        public BooleanMap GenerateTerrainMap(float Scale, float Density)
        {
            var ReturnResult = default(BooleanMap);
            var hmB = new clsHeightmap();
            var hmC = new clsHeightmap();

            hmB.GenerateNewOfSize(Terrain.TileSize.Y + 1, Terrain.TileSize.X + 1, Scale, 1.0D);
            hmC.Rescale(hmB, 0.0D, 1.0D);
            ReturnResult = new BooleanMap();
            ReturnResult.Convert_Heightmap(hmC, (int)((1.0D - Density) / hmC.HeightScale));
            return ReturnResult;
        }
Esempio n. 6
0
        public void GenerateMasterTerrain(ref sGenerateMasterTerrainArgs Args)
        {
            var X = 0;
            var Y = 0;
            var A = 0;
            int[,] TerrainType = null;
            float[,] Slope = null;

            var TerrainNum = 0;

            var bmA = new BooleanMap();
            var Layer_Num = 0;
            var LayerResult = new BooleanMap[Args.LayerCount];
            var bmB = new BooleanMap();
            double BestSlope = 0;
            double CurrentSlope = 0;
            var hmB = new clsHeightmap();
            var hmC = new clsHeightmap();

            double difA = 0;
            double difB = 0;
            var NewTri = default(bool);
            var CliffSlope = Math.Atan(255.0D * Constants.DefaultHeightMultiplier / (2.0D * (Args.LevelCount - 1.0D) * Constants.TerrainGridSpacing)) -
                             MathUtil.RadOf1Deg; //divided by 2 due to the terrain height randomization

            Tileset = Args.Tileset.Tileset;

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    difA = Math.Abs((Terrain.Vertices[X + 1, Y + 1].Height) - Terrain.Vertices[X, Y].Height);
                    difB = Math.Abs((Terrain.Vertices[X, Y + 1].Height) - Terrain.Vertices[X + 1, Y].Height);
                    if ( difA == difB )
                    {
                        if ( App.Random.Next() >= 0.5F )
                        {
                            NewTri = false;
                        }
                        else
                        {
                            NewTri = true;
                        }
                    }
                    else if ( difA < difB )
                    {
                        NewTri = false;
                    }
                    else
                    {
                        NewTri = true;
                    }
                    if ( !(Terrain.Tiles[X, Y].Tri == NewTri) )
                    {
                        Terrain.Tiles[X, Y].Tri = NewTri;
                    }
                }
            }

            for ( A = 0; A <= Args.LayerCount - 1; A++ )
            {
                Args.Layers[A].Terrainmap = new BooleanMap();
                if ( Args.Layers[A].TerrainmapDensity == 1.0F )
                {
                    Args.Layers[A].Terrainmap.ValueData.Value = new bool[Terrain.TileSize.Y, Terrain.TileSize.X];
                    Args.Layers[A].Terrainmap.ValueData.Size = Terrain.TileSize;
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            Args.Layers[A].Terrainmap.ValueData.Value[Y, X] = true;
                        }
                    }
                }
                else
                {
                    hmB.GenerateNewOfSize(Terrain.TileSize.Y, Terrain.TileSize.X, Convert.ToSingle(Args.Layers[A].TerrainmapScale), 1.0D);
                    hmC.Rescale(hmB, 0.0D, 1.0D);
                    Args.Layers[A].Terrainmap.Convert_Heightmap(hmC, (int)((1.0F - Args.Layers[A].TerrainmapDensity) / hmC.HeightScale));
                }
            }

            var Pos = new XYInt();

            TerrainType = new int[Terrain.TileSize.X, Terrain.TileSize.Y];
            Slope = new float[Terrain.TileSize.X, Terrain.TileSize.Y];
            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    //get slope
                    BestSlope = 0.0D;

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.25D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.25D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Pos.X = (int)((X + 0.75D) * Constants.TerrainGridSpacing);
                    Pos.Y = (int)((Y + 0.75D) * Constants.TerrainGridSpacing);
                    CurrentSlope = GetTerrainSlopeAngle(Pos);
                    if ( CurrentSlope > BestSlope )
                    {
                        BestSlope = CurrentSlope;
                    }

                    Slope[X, Y] = (float)BestSlope;
                }
            }
            for ( Layer_Num = 0; Layer_Num <= Args.LayerCount - 1; Layer_Num++ )
            {
                TerrainNum = Args.Layers[Layer_Num].TileNum;
                if ( TerrainNum >= 0 )
                {
                    //do other layer constraints
                    LayerResult[Layer_Num] = new BooleanMap();
                    LayerResult[Layer_Num].Copy(Args.Layers[Layer_Num].Terrainmap);
                    if ( Args.Layers[Layer_Num].WithinLayer >= 0 )
                    {
                        if ( Args.Layers[Layer_Num].WithinLayer < Layer_Num )
                        {
                            bmA.Within(LayerResult[Layer_Num], LayerResult[Args.Layers[Layer_Num].WithinLayer]);
                            LayerResult[Layer_Num].ValueData = bmA.ValueData;
                            bmA.ValueData = new BooleanMapDataValue();
                        }
                    }
                    for ( A = 0; A <= Layer_Num - 1; A++ )
                    {
                        if ( Args.Layers[Layer_Num].AvoidLayers[A] )
                        {
                            bmA.Expand_One_Tile(LayerResult[A]);
                            bmB.Remove(LayerResult[Layer_Num], bmA);
                            LayerResult[Layer_Num].ValueData = bmB.ValueData;
                            bmB.ValueData = new BooleanMapDataValue();
                        }
                    }
                    //do height and slope constraints
                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                            {
                                if ( Terrain.Vertices[X, Y].Height < Args.Layers[Layer_Num].HeightMin
                                     || Terrain.Vertices[X, Y].Height > Args.Layers[Layer_Num].HeightMax )
                                {
                                    LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                }
                                if ( Args.Layers[Layer_Num].IsCliff )
                                {
                                    if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                                    {
                                        if ( Slope[X, Y] < CliffSlope )
                                        {
                                            LayerResult[Layer_Num].ValueData.Value[Y, X] = false;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                        {
                            if ( LayerResult[Layer_Num].ValueData.Value[Y, X] )
                            {
                                TerrainType[X, Y] = TerrainNum;
                            }
                        }
                    }
                }
            }

            //set water tiles

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    if ( Args.Watermap.ValueData.Value[Y, X] )
                    {
                        if ( Slope[X, Y] < CliffSlope )
                        {
                            TerrainType[X, Y] = 17;
                        }
                    }
                }
            }

            //set border tiles to cliffs
            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= 2; X++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for ( X = Terrain.TileSize.X - 4; X <= Terrain.TileSize.X - 1; X++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }
            for ( X = 3; X <= Terrain.TileSize.X - 5; X++ )
            {
                for ( Y = 0; Y <= 2; Y++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
                for ( Y = Terrain.TileSize.Y - 4; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    TerrainType[X, Y] = Args.Tileset.BorderTextureNum;
                }
            }

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    Terrain.Tiles[X, Y].Texture.TextureNum = TerrainType[X, Y];
                }
            }
        }
Esempio n. 7
0
        public void Within(BooleanMap Interior, BooleanMap Exterior)
        {
            var Y = 0;
            var X = 0;
            var Flag = default(bool);

            SizeCopy(Interior);
            for ( Y = 0; Y <= Interior.ValueData.Size.Y - 1; Y++ )
            {
                for ( X = 0; X <= Interior.ValueData.Size.X - 1; X++ )
                {
                    if ( Interior.ValueData.Value[Y, X] )
                    {
                        Flag = false;
                        if ( Y > 0 )
                        {
                            if ( X > 0 )
                            {
                                if ( !Exterior.ValueData.Value[Y - 1, X - 1] )
                                {
                                    Flag = true;
                                }
                            }
                            if ( !Exterior.ValueData.Value[Y - 1, X] )
                            {
                                Flag = true;
                            }
                            if ( X < Interior.ValueData.Size.X - 1 )
                            {
                                if ( !Exterior.ValueData.Value[Y - 1, X + 1] )
                                {
                                    Flag = true;
                                }
                            }
                        }
                        if ( X > 0 )
                        {
                            if ( !Exterior.ValueData.Value[Y, X - 1] )
                            {
                                Flag = true;
                            }
                        }
                        if ( !Exterior.ValueData.Value[Y, X] )
                        {
                            Flag = true;
                        }
                        if ( X < Interior.ValueData.Size.X - 1 )
                        {
                            if ( !Exterior.ValueData.Value[Y, X + 1] )
                            {
                                Flag = true;
                            }
                        }
                        if ( Y < Interior.ValueData.Size.Y - 1 )
                        {
                            if ( X > 0 )
                            {
                                if ( !Exterior.ValueData.Value[Y + 1, X - 1] )
                                {
                                    Flag = true;
                                }
                            }
                            if ( !Exterior.ValueData.Value[Y + 1, X] )
                            {
                                Flag = true;
                            }
                            if ( X < Interior.ValueData.Size.X - 1 )
                            {
                                if ( !Exterior.ValueData.Value[Y + 1, X + 1] )
                                {
                                    Flag = true;
                                }
                            }
                        }
                        ValueData.Value[Y, X] = !Flag;
                    }
                }
            }
        }
Esempio n. 8
0
 public void SizeCopy(BooleanMap Source)
 {
     ValueData.Size.X = Source.ValueData.Size.X;
     ValueData.Size.Y = Source.ValueData.Size.Y;
     ValueData.Value = new bool[ValueData.Size.Y, ValueData.Size.X];
 }
Esempio n. 9
0
        public void Remove(BooleanMap Source, BooleanMap Remove)
        {
            var X = 0;
            var Y = 0;

            SizeCopy(Source);
            for ( Y = 0; Y <= Source.ValueData.Size.Y - 1; Y++ )
            {
                for ( X = 0; X <= Source.ValueData.Size.X - 1; X++ )
                {
                    if ( Remove.ValueData.Value[Y, X] )
                    {
                        ValueData.Value[Y, X] = false;
                    }
                    else
                    {
                        ValueData.Value[Y, X] = Source.ValueData.Value[Y, X];
                    }
                }
            }
        }
Esempio n. 10
0
        private clsResult FinishTextures()
        {
            var ReturnResult = new clsResult("", false);

            if ( cbxMasterTexture.Checked )
            {
                switch ( cboTileset.SelectedIndex )
                {
                    case 0:
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetArizona;
                        DefaultGenerator.TerrainStyle_Arizona.Watermap = Generator.GetWaterMap();
                        DefaultGenerator.TerrainStyle_Arizona.LevelCount = Generator.LevelCount;
                        Generator.Map.GenerateMasterTerrain(ref DefaultGenerator.TerrainStyle_Arizona);
                        DefaultGenerator.TerrainStyle_Arizona.Watermap = null;
                        break;
                    case 1:
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetUrban;
                        DefaultGenerator.TerrainStyle_Urban.Watermap = Generator.GetWaterMap();
                        DefaultGenerator.TerrainStyle_Urban.LevelCount = Generator.LevelCount;
                        Generator.Map.GenerateMasterTerrain(ref DefaultGenerator.TerrainStyle_Urban);
                        DefaultGenerator.TerrainStyle_Urban.Watermap = null;
                        break;
                    case 2:
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetRockies;
                        DefaultGenerator.TerrainStyle_Rockies.Watermap = Generator.GetWaterMap();
                        DefaultGenerator.TerrainStyle_Rockies.LevelCount = Generator.LevelCount;
                        Generator.Map.GenerateMasterTerrain(ref DefaultGenerator.TerrainStyle_Rockies);
                        DefaultGenerator.TerrainStyle_Rockies.Watermap = null;
                        break;
                    default:
                        ReturnResult.ProblemAdd("Error: bad tileset selection.");
                        btnGenerateLayout.Enabled = true;
                        return ReturnResult;
                }
                Generator.Map.TileType_Reset();
                Generator.Map.SetPainterToDefaults();
            }
            else
            {
                switch ( cboTileset.SelectedIndex )
                {
                    case 0:
                        Generator.Map.Tileset = App.Tileset_Arizona;
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetArizona;
                        break;
                    case 1:
                        Generator.Map.Tileset = App.Tileset_Urban;
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetUrban;
                        break;
                    case 2:
                        Generator.Map.Tileset = App.Tileset_Rockies;
                        Generator.GenerateTileset = DefaultGenerator.Generator_TilesetRockies;
                        break;
                    default:
                        ReturnResult.ProblemAdd("Error: bad tileset selection.");
                        btnGenerateLayout.Enabled = true;
                        return ReturnResult;
                }
                Generator.Map.TileType_Reset();
                Generator.Map.SetPainterToDefaults();
                var CliffAngle = Math.Atan(255.0D * Generator.Map.HeightMultiplier / (2.0D * (Generator.LevelCount - 1.0D) * Constants.TerrainGridSpacing)) -
                                 MathUtil.RadOf1Deg;
                var tmpBrush = new clsBrush((Math.Max(Generator.Map.Terrain.TileSize.X, Generator.Map.Terrain.TileSize.Y)) * 1.1D, clsBrush.enumShape.Square);
                var ApplyCliff = new clsApplyCliff();
                ApplyCliff.Map = Generator.Map;
                ApplyCliff.Angle = CliffAngle;
                ApplyCliff.SetTris = true;
                var Alignments = new clsBrush.sPosNum();
                Alignments.Normal = new XYInt((int)(Generator.Map.Terrain.TileSize.X / 2.0D),
                    (int)(Generator.Map.Terrain.TileSize.Y / 2.0D));
                Alignments.Alignment = Alignments.Normal;
                tmpBrush.PerformActionMapTiles(ApplyCliff, Alignments);
                bool[] RevertSlope = null;
                bool[] RevertHeight = null;
                var WaterMap = new BooleanMap();
                var bmTemp = new BooleanMap();
                var A = 0;
                WaterMap = Generator.GetWaterMap();
                RevertSlope = new bool[Generator.GenerateTileset.OldTextureLayers.LayerCount];
                RevertHeight = new bool[Generator.GenerateTileset.OldTextureLayers.LayerCount];
                for ( A = 0; A <= Generator.GenerateTileset.OldTextureLayers.LayerCount - 1; A++ )
                {
                    var with_2 = Generator.GenerateTileset.OldTextureLayers.Layers[A];
                    with_2.Terrainmap = Generator.Map.GenerateTerrainMap(with_2.Scale, with_2.Density);
                    if ( with_2.SlopeMax < 0.0F )
                    {
                        with_2.SlopeMax = (float)(CliffAngle - MathUtil.RadOf1Deg);
                        if ( with_2.HeightMax < 0.0F )
                        {
                            with_2.HeightMax = 255.0F;
                            bmTemp.Within(with_2.Terrainmap, WaterMap);
                            with_2.Terrainmap.ValueData = bmTemp.ValueData;
                            bmTemp.ValueData = new BooleanMapDataValue();
                            RevertHeight[A] = true;
                        }
                        RevertSlope[A] = true;
                    }
                }
                Generator.Map.MapTexturer(ref Generator.GenerateTileset.OldTextureLayers);
                for ( A = 0; A <= Generator.GenerateTileset.OldTextureLayers.LayerCount - 1; A++ )
                {
                    var with_3 = Generator.GenerateTileset.OldTextureLayers.Layers[A];
                    with_3.Terrainmap = null;
                    if ( RevertSlope[A] )
                    {
                        with_3.SlopeMax = -1.0F;
                    }
                    if ( RevertHeight[A] )
                    {
                        with_3.HeightMax = -1.0F;
                    }
                }
            }

            Generator.Map.LevelWater();

            Generator.Map.WaterTriCorrection();

            Generator.Map.SectorGraphicsChanges.SetAllChanged();
            Generator.Map.SectorUnitHeightsChanges.SetAllChanged();

            Generator.Map.Update();

            Generator.Map.UndoStepCreate("Generated Textures");

            if ( Generator.Map == _Owner.MainMap )
            {
                Program.frmMainInstance.PainterTerrains_Refresh(-1, -1);
                Program.frmMainInstance.MainMapTilesetChanged();
            }

            return ReturnResult;
        }
Esempio n. 11
0
        public BooleanMap GetWaterMap()
        {
            var ReturnResult = new BooleanMap();
            float BestDist = 0;
            var BestIsWater = default(bool);
            var Pos = new XYInt();
            float Dist = 0;
            var B = 0;
            var C = 0;
            var XY_int = new XYInt();
            var X = 0;
            var Y = 0;

            ReturnResult.Blank(Map.Terrain.TileSize.X + 1, Map.Terrain.TileSize.Y + 1);
            for ( Y = 0; Y <= Map.Terrain.TileSize.Y; Y++ )
            {
                for ( X = 0; X <= Map.Terrain.TileSize.X; X++ )
                {
                    BestDist = float.MaxValue;
                    Pos = new XYInt(X * Constants.TerrainGridSpacing, Y * Constants.TerrainGridSpacing);
                    for ( B = 0; B <= ConnectionCount - 1; B++ )
                    {
                        //If Not (Connections(B).PassageNodeA.IsOnBorder Or Connections(B).PassageNodeB.IsOnBorder) Then
                        if ( Connections[B].PassageNodeA.IsWater == Connections[B].PassageNodeB.IsWater )
                        {
                            //only do this if the waters are the same
                            //this is to make sure nodes that are connected are actually connected as water
                            XY_int = MathUtil.PointGetClosestPosOnLine(Connections[B].PassageNodeA.Pos, Connections[B].PassageNodeB.Pos, Pos);
                            Dist = Convert.ToSingle((XY_int - Pos).ToDoubles().GetMagnitude());
                            if ( Dist < BestDist )
                            {
                                BestDist = Dist;
                                if ( (Pos - Connections[B].PassageNodeA.Pos).ToDoubles().GetMagnitude() <=
                                     (Pos - Connections[B].PassageNodeB.Pos).ToDoubles().GetMagnitude() )
                                {
                                    BestIsWater = Connections[B].PassageNodeA.IsWater;
                                }
                                else
                                {
                                    BestIsWater = Connections[B].PassageNodeB.IsWater;
                                }
                            }
                        }
                    }
                    for ( C = 0; C <= PassageNodeCount - 1; C++ )
                    {
                        for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
                        {
                            Dist = Convert.ToSingle((Pos - PassageNodes[B, C].Pos).ToDoubles().GetMagnitude());
                            if ( Dist < BestDist )
                            {
                                BestDist = Dist;
                                BestIsWater = PassageNodes[B, C].IsWater;
                            }
                        }
                    }
                    ReturnResult.ValueData.Value[Y, X] = BestIsWater;
                }
            }
            return ReturnResult;
        }