private void UpdateMountain(MountainsModel mountain)
        {
            var index = Mountains.IndexOf(mountain);

            Mountains.Remove(mountain);
            Mountains.Insert(index, mountain);
        }
Example #2
0
    public virtual float[,] CreateMountains()
    {
        bool         canCreateMountain;
        List <float> heights = new List <float>();

        //Debug.Log(Length);

        for (int j = 0; j < Length; j++)
        {
            for (int i = 0; i < Length; i++)
            {
                if (IsInGrasslands(i, j))
                {
                    Map[j, i] = 0f;
                    continue;
                }
                canCreateMountain = true;

                foreach (var m in Mountains)
                {
                    canCreateMountain &= m.CanCreateNewMountain(i, j);
                }

                if (canCreateMountain && GetRandomChance(Hillyness) && Mountains.Count <= MaxNumberOfMountainsAtOneTime)
                {
                    var   radius = 0f;
                    float h      = GetRandomHillHeight();
                    h = (1 / (11 - h));
                    do
                    {
                        radius = (GetRandomHillWidth() / 10f) * Length / 2f;
                    }while (radius == 0 && Mathf.Asin(h * TerrainHeight / radius) * (180f / Mathf.PI) > 35);

                    //radius = radius * Length * Length;
                    var centerX = radius + i;
                    var centerY = radius + j;
                    Mountains.Add(new Mountain(radius, (int)centerX, (int)centerY, h * RegionBase.TerrainMaxHeight));
                }

                heights.Clear();
                var tempMountain = new Mountain[Mountains.Count];
                Mountains.CopyTo(tempMountain);

                foreach (var m in tempMountain)
                {
                    if (m.IsInMountain(i, j))
                    {
                        heights.Add(m.HeightAtPosition(i, j));
                    }
                    else if (m.CanRemoveMountain(i, j))
                    {
                        Mountains.Remove(m);
                    }
                }

                Map[j, i] = heights.Count == 0 ? 0f : GetMaxHeight(heights);
            }
        }
        return(Map);
    }
Example #3
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Black;
            float[,] map            = new float[40, 40];
            float[,] map2           = new float[40, 40];
            map  = Generator.PureRandom(40, 40, "asd");
            map2 = Generator.PureRandom(40, 40, "aaa");
            //map = GoniometricGenerator.sinWave(50, 50, 0.5f);
            map = TerrainMath.Multiply(map, 10);
            map = Smooth.SquareSmooth(map);
            map = Mountains.RemoveSmall(map, 6, 9);
            map = Water.RemoveSmall(map, 4, 7);

            map2 = TerrainMath.Multiply(map2, 10);
            map2 = Smooth.SquareSmooth(map);
            map2 = Mountains.RemoveSmall(map, 6, 9);
            map2 = Water.RemoveSmall(map, 4, 7);

            map = TerrainMath.Mix(map, map2);
            //map = TerrainMath.Clamp(map, 0, 9);
            map = Rounder.RoundDown(map);
            //map = Rounder.Round(map);
            VisualizeColor(map);

            Console.ReadLine();
        }
Example #4
0
        public static void _Main(string[] args)
        {
            var result = FilteringUtils.Search("S");     // insert here which letter is to be searched

            Console.WriteLine(result);

            var startingString = "Monte Falco, 1658, Parco Foreste Casentinesi ; Monte Falterona, 1654, Parco Foreste Casentinesi; Monte Fumaiolo, 1407, Appennino Tosco Emiliano";
            var result2        = Mountains.ListOfMountains(startingString); // less code here, only methods

            foreach (var item in result2)
            {
                Console.WriteLine(item.Split(',')[0].Trim());
            }
        }
Example #5
0
        private void LoadMap(Bytemap bitmap)
        {
            _tiles = new ITile[WIDTH, HEIGHT];

            for (int x = 0; x < WIDTH; x++)
            {
                for (int y = 0; y < HEIGHT; y++)
                {
                    ITile tile;
                    bool  special = TileIsSpecial(x, y);
                    switch (bitmap[x, y])
                    {
                    case 2: tile = new Forest(x, y, special); break;

                    case 3: tile = new Swamp(x, y, special); break;

                    case 6: tile = new Plains(x, y, special); break;

                    case 7: tile = new Tundra(x, y, special); break;

                    case 9: tile = new River(x, y); break;

                    case 10: tile = new Grassland(x, y); break;

                    case 11: tile = new Jungle(x, y, special); break;

                    case 12: tile = new Hills(x, y, special); break;

                    case 13: tile = new Mountains(x, y, special); break;

                    case 14: tile = new Desert(x, y, special); break;

                    case 15: tile = new Arctic(x, y, special); break;

                    default: tile = new Ocean(x, y, special); break;
                    }
                    _tiles[x, y] = tile;
                }
            }
        }
Example #6
0
        public void ChangeTileType(int x, int y, Terrain type)
        {
            bool special  = TileIsSpecial(x, y);
            bool road     = _tiles[x, y].Road;
            bool railRoad = _tiles[x, y].RailRoad;

            switch (type)
            {
            case Terrain.Forest: _tiles[x, y] = new Forest(x, y, special); break;

            case Terrain.Swamp: _tiles[x, y] = new Swamp(x, y, special); break;

            case Terrain.Plains: _tiles[x, y] = new Plains(x, y, special); break;

            case Terrain.Tundra: _tiles[x, y] = new Tundra(x, y, special); break;

            case Terrain.River: _tiles[x, y] = new River(x, y); break;

            case Terrain.Grassland1:
            case Terrain.Grassland2: _tiles[x, y] = new Grassland(x, y); break;

            case Terrain.Jungle: _tiles[x, y] = new Jungle(x, y, special); break;

            case Terrain.Hills: _tiles[x, y] = new Hills(x, y, special); break;

            case Terrain.Mountains: _tiles[x, y] = new Mountains(x, y, special); break;

            case Terrain.Desert: _tiles[x, y] = new Desert(x, y, special); break;

            case Terrain.Arctic: _tiles[x, y] = new Arctic(x, y, special); break;

            case Terrain.Ocean: _tiles[x, y] = new Ocean(x, y, special); break;
            }
            _tiles[x, y].Road     = road;
            _tiles[x, y].RailRoad = railRoad;
        }
Example #7
0
        private void MergeElevationAndLatitude(int[,] elevation, int[,] latitude)
        {
            Log("Map: Stage 3 - Merge elevation and latitude into the map");

            // merge elevation and latitude into the map
            for (int y = 0; y < HEIGHT; y++)
            {
                for (int x = 0; x < WIDTH; x++)
                {
                    bool special = TileIsSpecial(x, y);
                    switch (elevation[x, y])
                    {
                    case 0: _tiles[x, y] = new Ocean(x, y, special); break;

                    case 1:
                    {
                        switch (latitude[x, y])
                        {
                        case 0: _tiles[x, y] = new Desert(x, y, special); break;

                        case 1: _tiles[x, y] = new Plains(x, y, special); break;

                        case 2: _tiles[x, y] = new Tundra(x, y, special); break;

                        case 3: _tiles[x, y] = new Arctic(x, y, special); break;
                        }
                    }
                    break;

                    case 2: _tiles[x, y] = new Hills(x, y, special); break;

                    default: _tiles[x, y] = new Mountains(x, y, special); break;
                    }
                }
            }
        }
Example #8
0
	/**
	 * Called when the script is loaded, before the game starts
	 */
	void Awake () {
		S = this;
	}
Example #9
0
        public void FillTo(Generation.World.TimelineLayer component)
        {
            component.Age = Age;

            component.WorldTiles = new Generation.World.WorldTile[WorldMapResolution, WorldMapResolution];

            for (int i = 0; i < WorldMapResolution; i++)
            {
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.WorldTiles[i, j] = WorldTiles[i * WorldMapResolution + j];
                }
            }

            component.Civilizations = new List <Generation.World.Civilization>(Civilizations.Select(x => (Generation.World.Civilization)x));

            component.Continents = new List <Generation.World.Region>(Continents.Select(x => (Generation.World.Region)x));

            component.Islands = new List <Generation.World.Region>(Islands.Select(x => (Generation.World.Region)x));

            component.Mountains = new List <Generation.World.Region>(Mountains.Select(x => (Generation.World.Region)x));

            component.Forests = new List <Generation.World.Region>(Forests.Select(x => (Generation.World.Region)x));

            component.Deserts = new List <Generation.World.Region>(Deserts.Select(x => (Generation.World.Region)x));

            component.Swamps = new List <Generation.World.Region>(Swamps.Select(x => (Generation.World.Region)x));

            component.Chunks = Chunks;

            component.ElevationMap = new float[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.ElevationMap[i] = new float[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.ElevationMap[i][j] = ElevationMap[i * WorldMapResolution + j] / 255f;
                }
            }

            component.RiverMap = new bool[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.RiverMap[i] = new bool[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.RiverMap[i][j] = RiverMap[i * WorldMapResolution + j];
                }
            }


            component.RiverBorderMap = new bool[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.RiverBorderMap[i] = new bool[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.RiverBorderMap[i][j] = RiverBorderMap[i * WorldMapResolution + j];
                }
            }

            component.InlandWaterConnectivity = new TileForInlandWaterConnectivity[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.InlandWaterConnectivity[i] = new TileForInlandWaterConnectivity[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.InlandWaterConnectivity[i][j] = InlandWaterConnectivity[i * WorldMapResolution + j];
                }
            }



            component.BorderLines = new List <Generation.World.WaterBorderLine>();
            foreach (var borderLineStorage in BorderLines)
            {
                component.BorderLines.Add(borderLineStorage);
            }
        }
Example #10
0
        private void AgeAdjustments()
        {
            Log("Map: Stage 5 - Age adjustments");

            int x         = 0;
            int y         = 0;
            int ageRepeat = (int)(((float)800 * (1 + _age) / (80 * 50)) * (WIDTH * HEIGHT));

            for (int i = 0; i < ageRepeat; i++)
            {
                if (i % 2 == 0)
                {
                    x = Common.Random.Next(WIDTH);
                    y = Common.Random.Next(HEIGHT);
                }
                else
                {
                    switch (Common.Random.Next(8))
                    {
                    case 0: { x--; y--; break; }

                    case 1: { y--; break; }

                    case 2: { x++; y--; break; }

                    case 3: { x--; break; }

                    case 4: { x++; break; }

                    case 5: { x--; y++; break; }

                    case 6: { y++; break; }

                    default: { x++; y++; break; }
                    }
                    if (x < 0)
                    {
                        x = 1;
                    }
                    if (y < 0)
                    {
                        y = 1;
                    }
                    if (x >= WIDTH)
                    {
                        x = WIDTH - 2;
                    }
                    if (y >= HEIGHT)
                    {
                        y = HEIGHT - 2;
                    }
                }

                bool special = TileIsSpecial(x, y);
                switch (_tiles[x, y].Type)
                {
                case Terrain.Forest: _tiles[x, y] = new Jungle(x, y, special); break;

                case Terrain.Swamp: _tiles[x, y] = new Grassland(x, y); break;

                case Terrain.Plains: _tiles[x, y] = new Hills(x, y, special); break;

                case Terrain.Tundra: _tiles[x, y] = new Hills(x, y, special); break;

                case Terrain.River: _tiles[x, y] = new Forest(x, y, special); break;

                case Terrain.Grassland1:
                case Terrain.Grassland2: _tiles[x, y] = new Forest(x, y, special); break;

                case Terrain.Jungle: _tiles[x, y] = new Swamp(x, y, special); break;

                case Terrain.Hills: _tiles[x, y] = new Mountains(x, y, special); break;

                case Terrain.Mountains:
                    if ((x == 0 || _tiles[x - 1, y - 1].Type != Terrain.Ocean) &&
                        (y == 0 || _tiles[x + 1, y - 1].Type != Terrain.Ocean) &&
                        (x == (WIDTH - 1) || _tiles[x + 1, y + 1].Type != Terrain.Ocean) &&
                        (y == (HEIGHT - 1) || _tiles[x - 1, y + 1].Type != Terrain.Ocean))
                    {
                        _tiles[x, y] = new Ocean(x, y, special);
                    }
                    break;

                case Terrain.Desert: _tiles[x, y] = new Plains(x, y, special); break;

                case Terrain.Arctic: _tiles[x, y] = new Mountains(x, y, special); break;
                }
            }
        }