public ActionResult AjaxGetGroupById(int Id) { GroupModel objGroup = GroupMap.Map(_repoGroup.GetSingle(x => x.Id == Id)); List <ProvinceModel> lstProvince = new List <ProvinceModel>(); lstProvince = ProvinceMap.Map(_repoProvince.GetList(x => x.Country == objGroup.CountryName).ToList()); return(Json(new { status = "success", group = objGroup, lstProvince = lstProvince.ToArray() })); }
public sealed override void ResetMap() { map = new ProvinceMap(new TileMap(new GenerateHeight(Width, Height, Torus))); Selected = new List <Province>(); provinceColors = new Color[map.Tiles.Length]; for (int n = 0; n < provinceColors.Length; n++) { provinceColors[n] = Color.FromArgb(200 * n % 127 + 90, 500 * n % 127 + 90, 300 * n % 127 + 90); } }
public ActionResult AjaxGetProfileById(int Id) { UserProfileModel objProfile = UserProfileMap.Map(_repoUserProfile.GetSingle(x => x.Id == Id)); List <DisciplineModel> lstDiscipline = new List <DisciplineModel>(); lstDiscipline = DisciplineMap.Map(_repoDiscipline.GetList(x => x.CategoryId == objProfile.CategoryId).ToList()); List <ProvinceModel> lstProvince = new List <ProvinceModel>(); lstProvince = ProvinceMap.Map(_repoProvince.GetList(x => x.Country == objProfile.CountryName).ToList()); return(Json(new { status = "success", profile = objProfile, lstDiscipline = lstDiscipline.ToArray(), lstProvince = lstProvince.ToArray() })); }
public ActionResult AjaxGetProvinces(string country) { ProvinceModel[] arrProvinces = ProvinceMap.Map(_repoProvince.GetList(x => x.Country == country).DistinctBy(x => x.NAME_1).ToList()).ToArray(); if (arrProvinces != null) { return(Json(new { status = "success", provinceList = arrProvinces })); } else { return(Json(new { status = "error" })); } }
public World(WorldSettings worldSettings) { WorldSettings = worldSettings; ProvinceMap = new ProvinceMap(worldSettings); }
public void Generate(int numTerritories = 1500) { this.numTerritories = numTerritories; numPoints = numTerritories * 50; #region GenerateRandomPoints this.generatedMap.TerrainMap.LockBits(); ProvinceMap.LockBits(); points = new List <TerritoryPoint>(); int tot = (int)(((Width / RegionGridSize) * 0.4190996) * ((Height / RegionGridSize) * 0.4190996)); List <Vector2f> vpoints = new List <Vector2f>(); HashSet <Point> done = new HashSet <Point>(); // int numSeaPoints = numPoints / 140; int numSeaPoints = numPoints / 340; int seaStart = numPoints - numSeaPoints; for (int n = 0; n < numPoints - numSeaPoints; n++) { TerritoryPoint newPoint = null; bool duplicate = true; while (duplicate) { duplicate = false; do { newPoint = new TerritoryPoint(Rand.Next(Width), Rand.Next(Height)); } while (done.Contains(newPoint.Position)); if (generatedMap.TerrainMap.GetPixel(newPoint.Position.X, newPoint.Position.Y) == Color.FromArgb(255, 69, 91, 186)) { duplicate = true; continue; } done.Add(newPoint.Position); /* * foreach (TerritoryPoint p in points) * if (p.Position.X == newPoint.Position.X && p.Position.Y == newPoint.Position.Y) * { * duplicate = true; * break; * }*/ } if (newPoint != null) { vpoints.Add(new Vector2f(newPoint.Position.X, newPoint.Position.Y)); points.Add(newPoint); } } points.Clear(); Voronoi v = new Voronoi(vpoints, new Rectf(0, 0, Width, Height), 32); var coords = v.SiteCoords(); coords = coords.Where(c => generatedMap.TerrainMap.GetPixel((int)c.x, (int)c.y) != Color.FromArgb(255, 69, 91, 186)).ToList(); for (int n = 0; n < coords.Count; n++) { TerritoryPoint newPoint = null; bool duplicate = true; newPoint = new TerritoryPoint((int)coords[n].x, (int)coords[n].y); if (newPoint != null) { points.Add(newPoint); int xx = newPoint.Position.X / RegionGridSize; int yy = newPoint.Position.Y / RegionGridSize; List <TerritoryPoint> list = null; if (!Regions.ContainsKey(new Point(xx, yy))) { list = new List <TerritoryPoint>(); Regions[new Point(xx, yy)] = list; } else { list = Regions[new Point(xx, yy)]; } newPoint.Sea = false; list.Add(newPoint); } } #endregion #region GenerateTerritories List <TerritoryPoint> assigned = new List <TerritoryPoint>(); List <TerritoryPoint> unassigned = new List <TerritoryPoint>(); colours = new List <Color>(); var origPoints = new List <TerritoryPoint>(points); for (int n = 0; n < numTerritories; n++) { TerritoryPoint initialPoint = null; int i = 0;//rand.Next(points.Count()); while (initialPoint == null) { i = Rand.Next(origPoints.Count()); initialPoint = origPoints[i]; if (initialPoint.Owner != -1) { initialPoint = null; } else { i = points.IndexOf(initialPoint); } } bool requireSea = false; if (initialPoint.Sea) { requireSea = true; } foreach (TerritoryPoint p in points) { int dx = p.Position.X - initialPoint.Position.X; int dy = p.Position.Y - initialPoint.Position.Y; p.Distance = (float)Math.Sqrt(dx * dx + dy * dy); } points.Sort(SortByDistance); int c = 0; if (i >= seaStart) { c = 1; } else { for (c = 0; c < maxPointsPerTerritory; c++) { if (points[c].Owner != -1) { break; } } } if (c >= minPointsPerTerritory || i >= seaStart) { for (int c2 = 0; c2 < c; c2++) { if (points[c2].Owner == -1) { points[c2].Owner = n; origPoints.Remove(points[c2]); } } } else { n--; } } #endregion #region GenerateBitmap int[] provinceSize = new int[numTerritories + 100]; Color[] provinceColor = new Color[numTerritories + 100]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { float minDist = 1000000000; TerritoryPoint closest = null; if (generatedMap.TerrainMap.GetPixel(x, y) == Color.FromArgb(255, 69, 91, 186)) { ProvinceMap.SetPixel(x, y, Color.White); continue; } List <TerritoryPoint> list = new List <TerritoryPoint>(); bool found = false; int range = 1; while (!found) { for (int xx = -range; xx <= range; xx++) { for (int yy = -range; yy <= range; yy++) { int gx = x / RegionGridSize; int gy = y / RegionGridSize; int tx = xx + gx; int ty = yy + gy; if (Regions.ContainsKey(new Point(tx, ty))) { var l = Regions[new Point(tx, ty)]; list.AddRange(l.Where(p => p.Owner != -1)); } } } if (list.Count > 1) { break; } range++; } foreach (TerritoryPoint p in list) { int dx = p.Position.X - x; int dy = p.Position.Y - y; p.Distance = (float)Math.Sqrt(dx * dx + dy * dy); if (p.Owner != -1 && p.Distance < minDist) { closest = p; minDist = p.Distance; } } if (closest.Owner != -1) { provinceSize[closest.Owner]++; var col = colorMap[closest.Owner + 1]; ProvinceMap.SetPixel(x, y, col); } } } ProvinceMap.UnlockBits(); ProvinceMap.Save24(Globals.MapOutputTotalDir + "map\\provincestest.bmp"); #endregion }