protected Province selectProvince() { List <WeightedObjects <Province> > weighted_provinces = new List <WeightedObjects <Province> >(); List <Province> obsolete_provinces = new List <Province>(); foreach (Province province in PotentialProvinces) { bool add_province = true; add_province = selectionModifier(province); // Do not change the primary terrain feature more than once. if (!province.isDefault && isPrimary) { add_province = false; obsolete_provinces.Add(province); } foreach (Modifier modifier in province.ProvincialModifiers) { if (modifier.Forbids != null) { for (int i = 0; i < modifier.Forbids.Length; i++) { if (Tags.Contains(modifier.Forbids[i])) { add_province = false; } } } } if (add_province) { weighted_provinces.Add(new WeightedObjects <Province>(province)); } } foreach (Province province in obsolete_provinces) { PotentialProvinces.Remove(province); } foreach (WeightedObjects <Province> weighted_province in weighted_provinces) { weighted_province.Weight += 5; foreach (Modifier modifier in weighted_province.Object.ProvincialModifiers) { if (modifier.IncreasesWeight != null) { for (int i = 0; i < modifier.IncreasesWeight.Length; i++) { if (Tags.Contains(modifier.IncreasesWeight[i])) { weighted_province.Weight += WeightChange; } } } } // Primary terrain features are more likely to appear next to each other. if (isPrimary) { for (int i = 0; i < 8; i++) { SystemCoordinates coords = weighted_province.Object.Coordinates; coords = coords.GetNeighbour(i); if (coords.isInTileGridBounds()) { if (Program.State.ProvinceGrid[coords.X, coords.Y].PrimaryTerrainFeature.GetType() == weighted_province.Object.PrimaryTerrainFeature.GetType()) { weighted_province.Weight += WeightChange; } } } } } return(WeightedObjects <Province> .ChooseRandomObject(weighted_provinces, rnd)); }