public static void preReadProvinces(MyTexture image) { ProvinceNameGenerator nameGenerator = new ProvinceNameGenerator(); Color currentProvinceColor = image.GetPixel(0, 0); int provinceCounter = 0; for (int j = 0; j < image.getHeight(); j++) // circle by province { for (int i = 0; i < image.getWidth(); i++) { if (currentProvinceColor != image.GetPixel(i, j) //&& !blockedProvinces.Contains(currentProvinceColor) && !isProvinceCreated(currentProvinceColor)) { allProvinces.Add(new Province(nameGenerator.generateProvinceName(), provinceCounter, currentProvinceColor, Product.getRandomResource(false))); provinceCounter++; } currentProvinceColor = image.GetPixel(i, j); //game.updateStatus("Reading provinces.. x = " + i + " y = " + j); } } }
//private readonly Game game; //public VoxelGrid(int width, int height, float size, MyTexture texture, List<Province> blockedProvinces, IEnumerable<Province> provinces) public VoxelGrid(int width, int height, float size, MyTexture texture, IEnumerable <T> provinces) { this.width = width; this.height = height; //this.game = game; // this.resolution = resolution; gridSize = size; voxelSize = size / width; voxels = new Voxel <T> [width * height]; dummyX = new Voxel <T>(); dummyY = new Voxel <T>(); dummyT = new Voxel <T>(); for (int i = 0, y = 0; y < height; y++) { for (int x = 0; x < width; x++) { CreateVoxel(i, x, y, provinces.FirstOrDefault(t => t.ColorID == texture.GetPixel(x, y))); i++; } } }
public VoxelGrid(int width, int height, float size, MyTexture texture, List <Province> blockedProvinces, Game game, List <Province> provinces ) { this.width = width; this.height = height; this.game = game; // this.resolution = resolution; gridSize = size; voxelSize = size / width; voxels = new Voxel[width * height]; //voxelMaterials = new Material[voxels.Length]; dummyX = new Voxel(); dummyY = new Voxel(); dummyT = new Voxel(); //analyzingColor = color; //Color curColor, x1y1Color, x2y1Color, x1y2Color, x2y2Color; for (int i = 0, y = 0; y < height; y++) { for (int x = 0; x < width; x++) { //curColor = texture.GetPixel(x, y); //if (!blockedProvinces.Contains(curColor)) CreateVoxel(i, x, y, provinces.Find(province => province.getColorID() == texture.GetPixel(x, y))); i++; } } //for (int i = 0, y = 0; y < resolution; y++) //{ // for (int x = 0; x < resolution ; x++, i++) // { // x1y1Color = texture.GetPixel(x, y); // x2y1Color = texture.GetPixel(x + 1, y); // x1y2Color = texture.GetPixel(x, y + 1); // x2y2Color = texture.GetPixel(x + 1, y + 1); // if (!blockedProvinces.Contains(x1y1Color) // || !blockedProvinces.Contains(x2y1Color) // || !blockedProvinces.Contains(x1y2Color) // || !blockedProvinces.Contains(x2y2Color) // ) // CreateVoxel(i, x, y, x1y1Color); // else // CreateVoxel(i, x, y, Color.black); // } //} }
static List <Province> getSeaProvinces() { List <Province> res = new List <Province>(); if (!readMapFormFile) { Province seaProvince; for (int x = 0; x < map.getWidth(); x++) { seaProvince = Province.find(map.GetPixel(x, 0)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } seaProvince = Province.find(map.GetPixel(x, map.getHeight() - 1)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } for (int y = 0; y < map.getHeight(); y++) { seaProvince = Province.find(map.GetPixel(0, y)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } seaProvince = Province.find(map.GetPixel(map.getWidth() - 1, y)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } seaProvince = Province.find(map.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } if (Game.Random.Next(3) == 1) { seaProvince = Province.find(map.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } if (Game.Random.Next(20) == 1) { seaProvince = Province.find(map.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } } } else { foreach (var item in Province.allProvinces) { var color = item.getColorID(); if (color.g + color.b >= 200f / 255f + 200f / 255f && color.r < 96f / 255f) { //if (color.g + color.b + color.r > 492f / 255f) res.Add(item); } } } return(res); }
public static List <Province> getSeaProvinces(MyTexture mapTexture, bool useProvinceColors) { List <Province> res = new List <Province>(); if (!useProvinceColors) { Province seaProvince; for (int x = 0; x < mapTexture.getWidth(); x++) { seaProvince = FindProvince(mapTexture.GetPixel(x, 0)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } seaProvince = FindProvince(mapTexture.GetPixel(x, mapTexture.getHeight() - 1)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } for (int y = 0; y < mapTexture.getHeight(); y++) { seaProvince = FindProvince(mapTexture.GetPixel(0, y)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } seaProvince = FindProvince(mapTexture.GetPixel(mapTexture.getWidth() - 1, y)); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } seaProvince = FindProvince(mapTexture.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } if (Rand.Get.Next(3) == 1) { seaProvince = FindProvince(mapTexture.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } if (Rand.Get.Next(20) == 1) { seaProvince = FindProvince(mapTexture.getRandomPixel()); if (!res.Contains(seaProvince)) { res.Add(seaProvince); } } } } else { // Victoria 2 format foreach (var item in GetAllProvinces()) { var color = item.getColorID(); if (color.g + color.b >= 200f / 255f + 200f / 255f && color.r < 96f / 255f) { //if (color.g + color.b + color.r > 492f / 255f) res.Add(item); } } } return(res); }