private VoronoiMap GenerateMap() { _terrainMap = new TileTerrainTypeMap(Width, Height); for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { _terrainMap.Add(TileTerrainType.Water, x, y); } } CreateMap(); var voronoiFactory = new VoronoiFactory(new EvenlySpreadSiteGenerator()); var voronoiMap = voronoiFactory.CreateVoronoiMap(Height, Width, Regions); _lines = voronoiMap.Where(g => g is HalfEdge).Cast <HalfEdge>().SelectMany( edge => { var start = new Position(edge.Point.XInt, edge.Point.YInt); var end = new Position(edge.EndPoint.XInt, edge.EndPoint.YInt); var line = _map.DrawLine(start, end); return(line); }).ToList(); _vertices = voronoiMap.Where(g => g is Vertex).Cast <Vertex>().Select(v => new Position(v.Point.XInt, v.Point.YInt)).ToList(); return(voronoiMap); }
private bool LoadMapFromCache() { if (GameCache.Instance.ContainsMapInfo || MapMode != MapMode.InGame) { return(false); } var mapInfo = GameCache.Instance.CurrentGame.MapInfo; Height = mapInfo.Map.GetLength(1); Width = mapInfo.Map.GetLength(0); _hexGrid = new HexGrid(Height, Width, HexTile); _map = new HexMap(Height, Width); _terrainMap = new TileTerrainTypeMap(mapInfo.Map); CreateMap(); SetupMap(GameCache.Instance.CurrentGame.MapInfo); SkinMap(); return(true); }
public static MapInfo Create(IHexMap hexMap, TileTerrainTypeMap terrainMap) => new MapInfo { Map = terrainMap.Map, Tiles = hexMap.Select(t => new TileInfo { Position = t.Position, TileTerrainType = t.TileTerrainType, Resources = t.Resources, ProvinceInfo = new ProvinceInfo { Name = t.Province.Name, IsCapital = t.Province.IsCapital, OwnerInfo = t.Province.Owner != null ? new CountryInfo { Name = t.Province.Owner.Name } : null, ContinentInfo = t.Province.Owner != null ? new ContinentInfo { Name = t.transform.parent.name } : null } }).ToList() };
private void GenerateMap() { var mapGenerator = new ParticleDeposition { DropPoints = DropPoints, MaxParticles = MaxParticles, MinParticles = MinParticles, ParticleStabilityRadius = ParticleStabilityRadius, PassesCount = PassesCount }; var mapFactory = new MapFactory(mapGenerator) { DesertBelt = DesertBelt, FilterCount = FilterCount, MinHillsValue = MinHillsValue, MinMountainsValue = MinMountainsValue, PoleBelt = PoleBelt }; _terrainMap = mapFactory.CreateMap(_hexGrid.Width, _hexGrid.Height); CreateMap(); }
public TileTerrainTypeMap CreateMap(int width, int height) { if (MapGenerator == null) { return(null); } _equator = (int)Math.Round(height / 2m); var map = MapGenerator.Generate(width, height); var terrainMap = new TileTerrainTypeMap(width, height); var gaussianBlur = new GaussianBlur(); int[,] blurredMap = map; for (var i = 0; i < FilterCount; i++) { blurredMap = gaussianBlur.Filter(blurredMap); } var terrainTypes = new Dictionary <TileTerrainType, double> { { TileTerrainType.Bosk, 0.1 }, { TileTerrainType.Forest, 0.1 }, { TileTerrainType.Marsh, 0.02 }, { TileTerrainType.GrainField, 0.2 }, { TileTerrainType.Orchard, 0.05 }, { TileTerrainType.CattleMeadows, 0.05 }, { TileTerrainType.CottonField, 0.05 }, { TileTerrainType.SheepMeadows, 0.05 }, { TileTerrainType.StudFarm, 0.01 } }; var random = new System.Random(); for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var value = blurredMap[x, y]; // In the map border regions only use water if (value == 0 || (x < 2 || y < 2 || y > height - 3 || x > width - 3)) { terrainMap.Add(TileTerrainType.Water, x, y); continue; } if (value >= MinHillsValue && value < MinMountainsValue) { terrainMap.Add(TileTerrainType.Hills, x, y); continue; } if (value >= MinMountainsValue) { terrainMap.Add(TileTerrainType.Mountains, x, y); continue; } if (IsWithinDesertBelt(y)) { terrainMap.Add(TileTerrainType.Desert, x, y); continue; } if (IsWithinPoleBelt(y, height)) { terrainMap.Add(TileTerrainType.Tundra, x, y); continue; } TileTerrainType plainTerrain = TileTerrainType.Plain; // Generate busk, forest and agriculture tiles foreach (var terrainType in terrainTypes.Keys) { var randomValue = random.NextDouble(); if (randomValue > terrainTypes[terrainType]) { continue; } plainTerrain = terrainType; break; } terrainMap.Add(plainTerrain, x, y); } } return(terrainMap); }
// Use this for initialization void Start() { _mapObject = new GameObject("Map"); _continents = new List <GameObject>(); _mapInfoCache = new GameObject("MapInfoCache"); var map = _mapInfoCache.AddComponent <Assets.Scripts.Map.Map>(); MapInfo mapInfo = null; if (!GameCache.Instance.ContainsMapInfo && MapMode == MapMode.InGame) { mapInfo = GameCache.Instance.CurrentGame.MapInfo; // TODO: Replace debug text fields map.MapMode = MapMode; map.SelectedCountryText = SelectedCountryText; map.TerrainText = TerrainText; map.TileCountText = TileCountText; map.ProvinceText = ProvinceText; map.ProvinceCountText = ProvinceCountText; map.ResourcesText = ResourcesText; map.PositionText = PositionText; map.ContinentText = ContinentText; map.CountryText = CountryText; Height = mapInfo.Map.GetLength(1); Width = mapInfo.Map.GetLength(0); _hexGrid = new HexGrid(Height, Width, HexTile); _map = new HexMap(Height, Width); _terrainMap = new TileTerrainTypeMap(mapInfo.Map); _mapInfoCache = map.gameObject; CreateMap(); SetupMap(GameCache.Instance.CurrentGame.MapInfo); SkinMap(); return; } _hexGrid = new HexGrid(Height, Width, HexTile); _map = new HexMap(Height, Width); _continentCountryMapping = new Dictionary <GameObject, List <Country> >(); map.SelectedCountryText = SelectedCountryText; map.TerrainText = TerrainText; map.TileCountText = TileCountText; map.ProvinceText = ProvinceText; map.ProvinceCountText = ProvinceCountText; map.ResourcesText = ResourcesText; map.PositionText = PositionText; map.ContinentText = ContinentText; map.CountryText = CountryText; map.MapMode = MapMode; GenerateMap(); SetContinents(); Countries = new List <Country>(); _provinceCount = MajorCountries * ProvincesMajorCountries + MinorCountries * ProvincesMinorCountries; _tileCount = _continents.Sum(c => c.transform.childCount); _tileCountProvinces = _tileCount / _provinceCount; _tileCountMajorCountry = _tileCountProvinces * ProvincesMajorCountries; _tileCountMinorCountry = _tileCountProvinces * ProvincesMinorCountries; Debug.LogFormat("Tiles total: {0}", _tileCount); Debug.LogFormat("Provinces total: {0}", _provinceCount); Debug.LogFormat("Tiles per province: {0}", _tileCountProvinces); Debug.LogFormat("Tiles per major country: {0}", _tileCountMajorCountry); Debug.LogFormat("Tiles per minor country: {0}", _tileCountMinorCountry); Debug.LogFormat("Continents total: {0}", _continents.Count); SetupCountries(); SetupProvinces(); var resources = new Dictionary <Type, double> { { typeof(Coal), 0.3 }, { typeof(IronOre), 0.2 }, { typeof(Gold), 0.1 }, { typeof(Gemstone), 0.05 }, { typeof(Oil), 0.3 }, { typeof(Wood), 1 }, { typeof(Wool), 1 }, { typeof(Grain), 1 }, { typeof(Cotton), 1 }, { typeof(Cattle), 1 }, { typeof(Fruit), 1 }, { typeof(Horse), 1 } }; ResourceService.Instance.SpreadResources(_map, resources); if (MapMode == MapMode.InGame) { SkinMap(); } else { ColorCountries(); } // Store generated map in game cache mapInfo = new MapInfo { Map = _terrainMap.Map, Tiles = Countries.SelectMany(c => c.Provinces.SelectMany(p => p.HexTiles.Select(t => new TileInfo { Position = t.Position, TileTerrainType = t.TileTerrainType, Resources = t.Resources, ProvinceInfo = new ProvinceInfo { Name = t.Province.Name, IsCapital = t.Province.IsCapital, OwnerInfo = new CountryInfo { Name = t.Province.Owner.Name }, ContinentInfo = new ContinentInfo { Name = t.transform.parent.name } } }))).ToList() }; GameCache.Instance.SetMapInfo(mapInfo); GameCache.Instance.SetCountryNames(Countries.Select(c => c.Name)); }